java.util.Arrays.copyOf() method is in java.util.Arrays class. It copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length.
copyOf(int original, int newLength)
- original – original array
- newLength – copy of original array
Original Array 1 2 3 New array copy after modifications: 1 2 3 11 55
What happens if length of copied array is greater than original array?
The two arrays will have same values for all the indices that are valid in original array and new array.
However, the indices missing in original will have zero in copy in case the copied array length is more than the original array.
Original Array : 1 2 3 New array copy (of higher length): 1 2 3 0 0
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- EnumSet copyOf() Method in Java
- Java.util.Arrays.equals() in Java with Examples
- Arrays.toString() in Java with Examples
- Arrays.binarySearch() in Java with examples | Set 1
- Arrays.fill() in Java with Examples
- Arrays.sort() in Java with examples
- Arrays asList() method in Java with Examples
- Java 8 | Arrays parallelSort() method with Examples
- Arrays.binarySearch() in Java with examples | Set 2 (Search in subarray)
- util.Arrays vs reflect.Array in Java with Examples
- Java.util.Arrays.parallelSetAll(), Arrays.setAll() in Java
- Java.util.Arrays.deepEquals() in Java
- Java.util.Arrays.parallelPrefix in Java 8
- Java.util.Arrays.copyOfRange() in Java
- Arrays in Java