forked from tarunsinghofficial/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashmasp_java
26 lines (23 loc) · 883 Bytes
/
hashmasp_java
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
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class HashMapIteration {
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap<Integer,String> map = new HashMap<Integer,String>();
map.put(2, "Saket");
map.put(25, "Saurav");
map.put(12, "HashMap");
System.out.println(map.size());
System.out.println("While Loop:");
Iterator itr = map.entrySet().iterator();
while(itr.hasNext()) {
Map.Entry me = (Map.Entry) itr.next();
System.out.println("Key is " + me.getKey() + " Value is " + me.getValue());
}
System.out.println("For Loop:");
for(Map.Entry me2: map.entrySet()) {
System.out.println("Key is: " + me2.getKey() + " Value is: " + me2.getValue());
}
}
}