-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnsupported.java
More file actions
36 lines (33 loc) · 990 Bytes
/
Copy pathUnsupported.java
File metadata and controls
36 lines (33 loc) · 990 Bytes
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 chapter17.four;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class Unsupported {
static void test(String msg,List<String> list){
System.out.println("------"+msg+"------------");
Collection<String> c=list;
Collection<String> subList=list.subList(1, 4);
//copy of subList
Collection<String> c2=new ArrayList<String>(subList);
try {
c.retainAll(c2);
} catch (Exception e) {
// TODO: handle exception
System.out.println("retainAll"+e);
}
try {
c.removeAll(c2);
} catch (Exception e) {
// TODO: handle exception
System.out.println("removeALL"+e);
}
}
public static void main(String[] args) {
List<String> list=Arrays.asList("A B C D E F G H I J K L M ".split(" "));
test("Modifiable", new ArrayList<String>(list));
test("Arrays.asList()",list);
test("unmodifiableList()",Collections.unmodifiableList(new ArrayList<String>(list)));
}
}