Array: clone()
/*
Output:
Original size: 5
New size: 5
Original size: 9
New size: 9
* */
public class MainClass {
public static void main (String args[]) {
int array1[] = {1, 2, 3, 4, 5};
int array2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
System.out.println("Original size: " + array1.length);
System.out.println("New size: " + cloneArray(array1).length);
System.out.println("Original size: " + array2.length);
System.out.println("New size: " + cloneArray(array2).length);
}
static int[] cloneArray(int original[]) {
return (int[])original.clone();
}
}
Related examples in the same category
1. | Array: get(Object array, int index) | | |
2. | Array: getInt(Object array, int index) | | |
3. | Array: getLength(Object array) | | |
4. | Array: newInstance(Class componentType, int length) | | |
5. | Array: newInstance(Class> componentType, int... dimensions) | | |
6. | Array: set(Object array, int index, Object value) | | |
7. | Array: setInt(Object array, int index, int i) | | |
8. | Array: setLong(Object array, int index, long l) | | |
9. | Array: setShort(Object array, int index, short s) | | |