Contents
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

package lianxi;

import java.util.*;
import java.io.*;

public class lianxix {
public static void main(String[] args) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("yusijia", "dabai");
map.put("wutongyu", "datong");
map.put("tong", "bai");
System.out.println(map);
System.out.println("datong is in the map? " + map.containsKey("wutongyu"));
map.remove("tong");
System.out.println(map);

//返回此映射中所包含的键的 Set 视图。
Iterator it = map.keySet().iterator();//用迭代器遍历HashMap
while(it.hasNext()){
String key = (String)it.next();
System.out.println("key: " + key);
System.out.println("value: " + map.get(key));
System.out.println("The hashCode of value: " + map.get(key).hashCode());
}
System.out.println(map.size());//返回此映射中的键-值映射关系数。

//返回此映射所包含的值的 Collection 视图。
Iterator it2 = map.values().iterator();
while(it2.hasNext()){
String vaule = (String)it2.next();
System.out.println(vaule);
}
}
}
Contents