forked from KeepMoving/AlgorithmsLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapTest2.java
More file actions
37 lines (28 loc) · 862 Bytes
/
Copy pathMapTest2.java
File metadata and controls
37 lines (28 loc) · 862 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
35
36
37
package map;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class MapTest2
{
public static void main(String[] args)
{
Map m = new HashMap();
Person p1 = new Person();
Person p2 = new Person();
p1.setId("1");
p1.setName("name1");
p2.setId("2"); //注意这里设置了不同的ID
p2.setName("name2");
m.put(p1, "person1");
m.put(p2, "person2");
System.out.println("Map m's size :" + m.size());
p2.setId("1");
System.out.println("Map m's size :" + m.size());
for(Object o :m.entrySet())
{
Entry e = (Entry)o;
System.out.println("key:"+ e.getKey());
System.out.println("value:"+ e.getValue());
}
}
}