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.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- EnumSet copyOf() Method in Java
- Java.util.Arrays.parallelSetAll(), Arrays.setAll() in Java
- Java.util.Arrays.equals() in Java with Examples
- Arrays.sort() in Java with examples
- Arrays.fill() in Java with Examples
- Arrays.toString() in Java with Examples
- Arrays.binarySearch() in Java with examples | Set 1
- Arrays.binarySearch() in Java with examples | Set 2 (Search in subarray)
- Java 8 | Arrays parallelSort() method with Examples
- Arrays asList() method in Java with Examples
- util.Arrays vs reflect.Array in Java with Examples
- Java.util.Arrays.deepEquals() in Java
- Java.util.Arrays.copyOfRange() in Java
- Java.util.Arrays.parallelPrefix in Java 8
- Arrays in Java
- Final arrays in Java
- How to compare two arrays in Java?
- Arrays class in Java
- Arrays.deepToString() in Java with Example
- Arrays in Java