-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestHashTable.java
More file actions
47 lines (37 loc) · 1.27 KB
/
Copy pathTestHashTable.java
File metadata and controls
47 lines (37 loc) · 1.27 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
package collection;
import java.util.*;
public class TestHashTable {
public static void main(String[] args) {
Hashtable<Integer,String> th = new Hashtable<Integer,String>();
Hashtable<Integer,String> th1 = new Hashtable<Integer,String>();
th.put(1001, "chenna");
th.put(20002, "Kanna");
th.put(3003, "Jing");
th.put(4309, "Serey");
// update
th.put(5005,"Kaka");
// clear
th.clear();
// remove
th.remove(1001);
// Searrch
boolean b = th.containsKey(4309);
if(b){
System.out.println("Search found");
}else{
System.out.println("Search not found");
}
// Size
System.out.println("Size of list"+th.size());
// clone
th1 = (Hashtable<Integer, String>)th.clone();
System.out.println("Key\tValue");
for(Map.Entry<Integer ,String> temp : th.entrySet()){
System.out.println("Key ="+temp.getKey()+" Value ="+temp.getValue());
}
System.out.println("Clone");
for(Map.Entry<Integer ,String> temp : th1.entrySet()){
System.out.println("Key ="+temp.getKey()+" Value ="+temp.getValue());
}
}
}