哈喽,欢迎来到小朱课堂,下面开始你的学习吧!
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());
}
}
}
}
搬砖路上,希望对你有帮助!可以关注一下哟,持续更新哟! 有问题可以私聊博主,快发表一下你的看法吧!