-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathHashMapDemo.java
More file actions
54 lines (38 loc) · 1.14 KB
/
HashMapDemo.java
File metadata and controls
54 lines (38 loc) · 1.14 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
48
49
50
51
52
53
54
package com.map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
public class HashMapDemo {
public static void main(String[] args) {
HashMap<Integer,String> map = new HashMap<Integer, String>();
map.put(new Integer(10), "Sakshi");
map.put(new Integer(20), "Palak");
map.put(40, "prachi");
map.put(40,"Ritesh");
map.put(50, "prachi");
map.put(null, "Hi");
map.put(null, "Hello");
map.put(60, null);
map.put(70,null);
//String s = map.get(10);
Set<Integer> keys = map.keySet();
for(Integer k : keys)
{
System.out.println("Key :"+k+" Value: "+map.get(k));
}
HashMap<Employee, String> empmap = new HashMap<Employee, String>();
Employee emp1=new Employee(101,"sakshi",1290);
Employee emp2=new Employee(101,"sakshi",1290);
Employee emp3=new Employee(103,"palak",34324);
empmap.put(emp1, "Hi");
empmap.put(emp2, "Hello");
empmap.put(emp3, "Hi");
Set<Employee> empset=empmap.keySet();
Iterator<Employee> it = empset.iterator();
while(it.hasNext())
{
Employee emp = it.next();
System.out.println("Key :"+emp+" Value: "+empmap.get(emp));
}
}
}