-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMapExample.java
More file actions
34 lines (32 loc) · 838 Bytes
/
HashMapExample.java
File metadata and controls
34 lines (32 loc) · 838 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 collection.Map;
import java.util.HashMap;
import java.util.Map;
/*
* Output-
Value Associated with key 'two'= 2
Keysets: [six, one, seven, two]
Entry of map: [six=6, one=1, seven=7, two=2]
Size of map: 4
one : 1
{six=6, one=1, seven=7, two=2}
*
*/
public class HashMapExample {
public static void main(String[] args) {
Map<String,Integer> m=new HashMap<>();
m.put("six", 6);
m.put("one", 1);
m.put("two", 2);
m.put("seven", 7);
System.out.print("Value Associated with key 'two'= "+m.get("two")+"\n");
System.out.print("Keysets: "+m.keySet()+"\n");
System.out.print("Entry of map: "+m.entrySet()+"\n");
System.out.println("Size of map: "+m.size());
if(m.containsKey("one")) {
Integer x=m.get("one");
System.out.println("one : "+x);
}
if(!m.isEmpty())
System.out.println(m);
}
}