public class HashMapTest {
public static void main(String args[ ]){
Map<String, String> map = new HashMap<>();
for (int i = 0; i < 10; i++) {
map.put("hello world"+i, "我爱数学"+i);
}
Set<String> set = map.keySet();
Iterator<String> iterator = set.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
Collection<String> collection = map.values();
Iterator<String> iterator2 = collection.iterator();
while(iterator2.hasNext()){
System.out.println(iterator2.next());
}
}
}
结果如下:
网友评论