Map的迭代输出
1 package test; 2 import java.util.Collection; 3 import java.util.HashMap; 4 import java.util.Iterator; 5 import java.util.Map; 6 import java.util.Set; 7 public class Test 8 { 9 public static void main(String[] args) throws Exception 10 { 11 Map<String,String> map = new HashMap(); 12 map.put("hello", "world"); 13 map.put("hello1", "world1"); 14 map.put("hello2", "world2"); 15 map.put("hello3", "world3"); 16 map.put("hello4", "world4"); 17 String str = map.get("hello"); 18 boolean containsKey = map.containsKey("hello"); 19 boolean containsValue = map.containsValue("world"); 20 Set<String> keySet = map.keySet(); 21 Collection<String> values = map.values(); 22 23 Iterator<String> iter = values.iterator(); 24 while(iter.hasNext()){ 25 String s = iter.next(); 26 System.out.println(s+"E"); 27 } 28 29 } 30 }