首页 > 代码库 > 遍历map

遍历map

map

package l6.e5.map;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;public class MapTest5My2{	public static void main(String[] args)	{		HashMap<String,String> map = new HashMap<String,String>();				map.put("a", "aa");		map.put("b", "bb");		map.put("c", "cc");		map.put("d", "dd");				Set<String> set = map.keySet();		//keyset 1 		for (String key : set) {			System.out.println("key= "+ key + " and value= "http://www.mamicode.com/+ map.get(key));":"+value);					}				//entryset		Set<Map.Entry<String, String>> set2= map.entrySet();				for (Map.Entry<String, String> entry : set2) {			System.out.println("key :" + entry.getKey() + " and value :" + entry.getValue());		}							}}

  

遍历map