June 2025
Intermediate to advanced
1129 pages
53h
English
Arrays are objects, but they “can’t do” much. In many other programming languages, such as JavaScript, the situation is quite different. In Java, the methods are swapped out, especially in java.util.Arrays .
To create a copy of an array with the same size and element type, you can use the object method clone() . [ 108 ]
This method clones—in our case copies—the elements of an array object into a new array.
The following code finds out whether an array is sorted or not:
int[] numbers = { 1, 2, 99 };int[] numbersClone = numbers.clone();Arrays.sort( numbersClone );System.out.println( Arrays.equals( numbers, numbersClone ) ); // true
Arrays.sort(...) ...
Read now
Unlock full access