-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashSetEx.java
More file actions
53 lines (40 loc) · 1.32 KB
/
Copy pathHashSetEx.java
File metadata and controls
53 lines (40 loc) · 1.32 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
import java.util.*;
import static java.lang.System.out;
/**
* Created by santosh on 1/29/2017.
*/
public class HashSetEx {
public static void main(String[] args) {
Set<String> stringList =
new HashSet(Arrays.asList(new String[]{"Ruthvik","Santosh","Nihanth","Nihanth"}));
addDuplicates(stringList);
iterateSet(stringList);
copySet(stringList);
}
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));
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()+" ");
}
}
}