/**
* 遍历hashmap的键值,通过 keySet()方法
* @author gulijiang
*
*/
public class HashMapTest1 {
public static void main(String[] args) {
HashMap hashMap = new HashMap();
hashMap.put("a", "aa");
hashMap.put("b","bb");
hashMap.put("c","cc");
print(hashMap);
}
private static void print(HashMap hashMap) {
Set set = hashMap.keySet();
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
String key = (String)iterator.next();
System.out.println(key);
System.out.println(hashMap.get(key));
}
}
}
遍历hashmap的键值一,通过 keySet()方法
最新推荐文章于 2021-02-25 06:25:48 发布