码迷,mamicode.com
首页 > 其他好文 > 详细

map转换成list

时间:2014-07-26 00:12:16      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:blog   http   java   io   2014   for   re   c   

Java代码如下:

package Test01;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Test05 {

	// map转换成list
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static List mapTransitionList(Map map) {
		List list = new ArrayList();
		Iterator iter = map.entrySet().iterator(); // 获得map的Iterator
		while (iter.hasNext()) {
			Entry entry = (Entry) iter.next();			
			list.add(entry.getKey());
			list.add(entry.getValue());
		}
		return list;
	}

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		@SuppressWarnings("rawtypes")
		Map map = new HashMap();
		map.put("aaa", 11);
		map.put("bbb", "22ss");
		map.put("ccc", "汉字");
		@SuppressWarnings("rawtypes")
		List list = mapTransitionList(map);
		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i) + " ");
		}
	}
}

 

代码运行后效果如下:

bubuko.com,布布扣

map转换成list,布布扣,bubuko.com

map转换成list

标签:blog   http   java   io   2014   for   re   c   

原文地址:http://www.cnblogs.com/henuyuxiang/p/3868353.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!