map转换成list

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) + " ");
		}
	}
}

 

代码运行后效果如下:

posted @ 2014-07-25 16:24  岁月淡忘了谁  阅读(48286)  评论(0编辑  收藏  举报