-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionMethod.java
More file actions
53 lines (44 loc) · 1.46 KB
/
CollectionMethod.java
File metadata and controls
53 lines (44 loc) · 1.46 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package btp.oneP;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class CollectionMethod {
public static void main(String[] args) {
Collection<String> c = new ArrayList<String>();
c.addAll(Countries.names(6));
c.add("ten");
c.add("eleven");
System.out.println(c);
Object[] array = c.toArray();
String[] str = c.toArray(new String[0]);
System.out.println(Arrays.toString(array));
System.out.println(Arrays.toString(str));
System.out.println("Collections.max(c) = "+Collections.max(c));
System.out.println("Collections.min(c) = "+Collections.min(c));
Collection<String> c2 = new ArrayList<String>();
c2.addAll(Countries.names(6));
c.addAll(c2);
System.out.println(c);
c.remove(Countries.DATA[0][0]);
System.out.println(c);
c.removeAll(c2);
System.out.println(c);
c.addAll(c2);
System.out.println(c);
String val = Countries.DATA[3][0];
System.out.println("c.contains("+val+")="+c.contains(val));
System.out.println("c.containsAll(c2)="+c.containsAll(c2));
Collection<String> c3 = ((List<String>)c).subList(3, 5);
c2.retainAll(c3);
System.out.println(c2);
c2.removeAll(c3);
System.out.println("c2.isEmpty()="+c2.isEmpty());
c = new ArrayList<String>();
c.addAll(Countries.names(6));
System.out.println(c);
c.clear();
System.out.println("after c.clear():"+c);
}
}