-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashSet
More file actions
52 lines (43 loc) · 1.12 KB
/
HashSet
File metadata and controls
52 lines (43 loc) · 1.12 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
package Collections;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Hashset {
public static void main(String[] args) {
Set<String> h = new HashSet<String>();
h.add("srikanth");
h.add("chowdary");
h.add("vamsi");
h.add("shekar");
h.add(null);
h.add(null);
h.add("vamsi"); //duplicate element
System.out.println(h.size()); // size of the hashtable
System.out.println(h.isEmpty()); // returns boolean value;
System.out.println(h.contains("chowdary")); // return boolean value true or false; // true
// sort(h);
Iterator<String> itr = h.iterator();
while(itr.hasNext()) {
System.out.print(itr.next()+" ");
}
System.out.println();
System.out.println(h.remove("cho"));
Collection<String> h1 = new HashSet<String>();
h1.add("1");
h1.add("2");
h1.add("4");
h1.add("5");
h1.add("6");
h1.add("7");
h1.add("89");
h1.add("5");
h1.addAll(h);
Iterator<String> itr1 = h1.iterator();
while(itr1.hasNext()) {
System.out.print(itr1.next()+" ");
}
h1.clear();
}
}