-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeSetEx.java
More file actions
57 lines (45 loc) · 1.54 KB
/
Copy pathTreeSetEx.java
File metadata and controls
57 lines (45 loc) · 1.54 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
54
55
56
57
import java.util.*;
import static java.lang.System.out;
/**
* Created by santosh on 1/29/2017.
*/
public class TreeSetEx {
public static void main(String[] args) {
TreeSet<String> stringList = new TreeSet(Arrays.asList(new String[]{"Ruthvik","Santosh","Nihanth","Nihanth"}));
// addDuplicates(stringList);
// iterateSet(stringList);
// copySet(stringList);
out.println(stringList);
out.println(stringList.pollFirst());
out.println(stringList);
out.println(stringList.pollLast());
out.println(stringList);
out.println(stringList.first());
out.println(stringList.last());
}
private static void copySet(Set<String> stringList) {
}
private static void addDuplicates(Set<String> stringList) {
out.println(stringList.add("Sravanthi"));
out.println(stringList.add("Santosh"));
out.println(stringList.add(""));
out.println(stringList.add(null));
}
public static void iterateSet(Set<String> stringList){
// first type of iterating
out.println("first type of iteration");
stringList.forEach(out::print);
//second type of iterating
out.println("\n Second type of iteration");
for (String str:stringList){
out.print(str+" ");
}
//third type
out.println("\n thrid type of iteration");
Iterator iterator = stringList.iterator();
while(iterator.hasNext())
{
out.print(iterator.next()+" ");
}
}
}