-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModifyingArraysAsList.java
More file actions
36 lines (29 loc) · 1.21 KB
/
ModifyingArraysAsList.java
File metadata and controls
36 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package holding;
/**
* RUN:
* javac holding/ModifyingArraysAsList.java && java holding.ModifyingArraysAsList
* OUTPUT:
* Before shuffle: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
* After shuffle: [4, 6, 3, 1, 8, 7, 2, 5, 10, 9]
* Array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
* Before shuffle: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
* After shuffle: [9, 1, 6, 3, 7, 2, 5, 10, 4, 8]
* Array: [9, 1, 6, 3, 7, 2, 5, 10, 4, 8]
*/
import java.util.*;
public class ModifyingArraysAsList {
public static void main(String[] args) {
Random rand = new Random(47);
Integer[] ia = {1,2,3,4,5,6,7,8,9,10};
List<Integer> list1 = new ArrayList<Integer>(Arrays.asList(ia));
System.out.println("Before shuffle: " + list1);
Collections.shuffle(list1, rand);
System.out.println("After shuffle: " + list1);
System.out.println("Array: " + Arrays.toString(ia));
List<Integer> list2 = Arrays.asList(ia);
System.out.println("Before shuffle: " + list2);
Collections.shuffle(list2, rand);
System.out.println("After shuffle: " + list2);
System.out.println("Array: " + Arrays.toString(ia));
}
}