`

Map to List, List to Map,Map 转 List

 
阅读更多

1. Map to List

   Init Map

Map<String,String> map = new HashMap<String,String>();
		map.put("first", "firstvalue");
		map.put("second", "secondvalue");
		map.put("third", "thirdvalue");

 

a) get key List

   From a Set returned by the map.keySet method:

List<String> keyList = new ArrayList<String>(map.keySet());
		for(String key: keyList){
			System.out.println("key:"+key);
		}

 

b) get value List

   From a Collection returned by the map.values method:

List<String> valueList = new ArrayList<String>(map.values());
		for(String value: valueList){
			System.out.println("value:"+value);
		}

 

c) get entry List
    From a Entry return by map.entrySet method:

List<Map.Entry<String,String>> entryList = new ArrayList<Map.Entry<String,String>>(map.entrySet());
	for(Map.Entry entry: entryList){
	   System.out.println("entry key:"+entry.getKey()+"entry value:"+entry.getValue());
	}

 

 2. List to Map

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics