public class HashMapExample {
public static void main(String[] args) {
HashMap hm = new HashMap<Object,String>();
hm.put(new Integer(2),"two");
hm.put(new Integer(3),"threee");
hm.put(new Integer(1),"one");
hm.put(new Integer(4),"four");
Set s = hm.entrySet();
Iterator it =s.iterator();
while(it.hasNext()) {
Map.Entry m = (Map.Entry)it.next();
int key = (Integer)m.getKey();
String value = (String)m.getValue();
System.out.println("key: " + key);
System.out.println("value:" + value);
}
}
}hashmap example
最新推荐文章于 2021-10-28 10:13:02 发布
本文展示了一个使用Java实现的HashMap实例,详细介绍了如何插入、获取键值对,并通过entrySet进行遍历。
642

被折叠的 条评论
为什么被折叠?



