-
Notifications
You must be signed in to change notification settings - Fork 1
/
set.java
40 lines (32 loc) · 921 Bytes
/
set.java
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
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class set {
public static void main(String[] args) {
Set<Integer> set = new HashSet<Integer>();
Set<Integer> sset = new TreeSet<Integer>();
// Adding elements into the set
set.add(6);
set.add(7);
set.add(10);
set.add(10);
set.add(54);
set.add(87);
set.add(54);
set.add(43);
sset.addAll(set);
Iterator<Integer> it = set.iterator();
while (it.hasNext()) {
System.out.print(it.next() + " ");
}
System.out.println();
for (int s : set) {
System.out.print(s + " ");
}
System.out.println();
set.remove(7);
System.out.println("Set: " + set);
System.out.println("Sorted Set: " + sset);
}
}