-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedHashMapExample.java
More file actions
32 lines (26 loc) · 916 Bytes
/
LinkedHashMapExample.java
File metadata and controls
32 lines (26 loc) · 916 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
package collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
public class LinkedHashMapExample {
public static void main(String[] args) {
// HashMap Declaration
LinkedHashMap<Integer, String> lhmap = new LinkedHashMap<Integer, String>();
// Adding elements to LinkedHashMap
lhmap.put(22, "Core Java");
lhmap.put(33, "Adv Java");
lhmap.put(1, "Spring");
lhmap.put(2, "Hibernate");
lhmap.put(100, "Maven");
// Generating a Set of entries
Set<Entry<Integer, String>> set = lhmap.entrySet();
// Displaying elements of LinkedHashMap
Iterator<Entry<Integer, String>> iterator = set.iterator();
while (iterator.hasNext()) {
Entry<Integer, String> me = iterator.next();
System.out.print("Key is: " + me.getKey() + "& Value is: " + me.getValue() + "\n");
}
}
}