-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashtableValues.java
More file actions
34 lines (26 loc) · 793 Bytes
/
HashtableValues.java
File metadata and controls
34 lines (26 loc) · 793 Bytes
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
package datastructure.hashtable;
import java.util.*;
public class HashtableValues {
public static void main(String[] args) {
Hashtable<String, String> ht = new Hashtable<String, String>();
ht.put("3", "three");
ht.put("100", "thundred");
ht.put("12", "tweleve");
Enumeration<String> e = ht.keys();
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + " ");
}
System.out.println();
Enumeration<String> en = ht.elements();
while (en.hasMoreElements()) {
System.out.print(en.nextElement() + " ");
}
System.out.println();
// Sort the content of hashtable
List<String> listOfKeys = new ArrayList<String>(ht.keySet());
Collections.sort(listOfKeys);
for (String key : listOfKeys) {
System.out.println(key + " : " + ht.get(key));
}
}
}