集合之HashMap的简单使用

2018-05-23  本文已影响8人  Joy_yang17
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());
      }
      
  }
}

结果如下:

上述代码的运行结果.png
上一篇下一篇

猜你喜欢

热点阅读