08-10-2016, 04:00 PM
Fur Java:
Result:
Code:
public class CopyArrays {
static ArrayList arr1 = new ArrayList();
static ArrayList arr2;
private static ArrayList<Integer> randomize(ArrayList<Integer> array) {
Integer cnt1;
Random rndm = new Random();
for (int i = 0; i < 10; i++) {
cnt1 = rndm.nextInt(100);
array.add(cnt1);
}
return array;
}
public static void main(String[] args) {
randomize(arr1);
arr2 = (ArrayList<String>) arr1.clone();
arr1.set(9, "-7");
System.out.println("Array 1: " + arr1 + "\n" + "Array 2: " + arr2);
}
}
Result:
Quote:Array 1: [77, 38, 3, 37, 58, 48, 27, 18, 16, -7]
Array 2: [77, 38, 3, 37, 58, 48, 27, 18, 16, 42]