list中存放map实例

List中存放Map遍历输出的实例

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

public class ListMap {

	static List<Map> lis = new ArrayList<Map>();
	static Map<Integer, String> map = new HashMap<Integer, String>();
	static Map<Integer, Integer> ma = new HashMap<Integer, Integer>();

	public static void main(String[] args) {

		map.put(1, "aaa");
		map.put(2, "bbb");
		map.put(3, "ccc");

		ma.put(1, 1);
		ma.put(2, 2);
		ma.put(3, 3);

		lis.add(map);
		lis.add(ma);

		for (Map m : lis) {
			Iterator<Map.Entry<Object, Object>> it = m.entrySet().iterator();
			while (it.hasNext()) {
				Map.Entry<Object, Object> entry = it.next();
				System.out.println(entry.getKey() + " " + entry.getValue());
			}
		}
	}

}
    原文作者:JLUnanfeiyan
    原文地址: https://blog.csdn.net/qq_24877569/article/details/52154507
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞