直接上代码
1 @Test 2 public void test3(){ 3 4 Map<Integer, String> m = new HashMap<Integer, String>(); 5 m.put(1, "one"); 6 m.put(2, "two"); 7 m.put(3, "three"); 8 Set<Map.Entry<Integer, String>> set = m.entrySet(); 9 Iterator<Map.Entry<Integer, String>> i = set.iterator(); 10 while(i.hasNext()){ 11 Entry<Integer, String> entry = i.next(); 12 int key = entry.getKey(); 13 String value = entry.getValue(); 14 System.out.println(key+"="+value); 15 16 } 17 18 } 19 20 @Test 21 public void test4(){ 22 23 Map<Integer, String> m = new HashMap<Integer, String>(); 24 m.put(1, "one"); 25 m.put(2, "two"); 26 m.put(3, "three"); 27 Set<Integer> set = m.keySet(); 28 Iterator<Integer> i = set.iterator(); 29 while(i.hasNext()){ 30 int key = i.next(); 31 String value = m.get(key); 32 System.out.println(key+"="+value); 33 } 34 }
原文地址:https://www.cnblogs.com/Vamps0911/p/10774785.html
时间: 2024-11-15 06:05:42