标签:
将List变成Map结构体,下面的文字是没有水平!
写作方法传送前土壤很长一段时间。我不知道有没有好的解决办法。我们也希望提供!
Map<String, String> map1 = new HashMap<String, String>(); map1.put("a", "1"); map1.put("b", "3"); map1.put("c", "5"); Map<String, String> map2 = new HashMap<String, String>(); map2.put("a", "2"); map2.put("b", "4"); map2.put("c", "6"); List<Map<String, String>> lm = new ArrayList<Map<String, String>>(); lm.add(map1); lm.add(map2); Map<String, List<String>> ml = new HashMap<String, List<String>>(); for (int i = 0; i < lm.size(); i++) { Map<String, String> m = lm.get(i); Iterator<Map.Entry<String, String>> it = m.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> entry = it.next(); List<String> al = ml.get(entry.getKey()); if (al == null) { al = new ArrayList<String>(); } al.add(entry.getValue()); ml.put(entry.getKey(), al); } } System.out.println(ml);// {b=[3, 4], c=[5, 6], a=[1, 2]}
版权声明:本文博主原创文章,博客,未经同意不得转载。
List<Map<String, String>> 开启 Map<String, List<String>>
标签:
原文地址:http://www.cnblogs.com/gcczhongduan/p/4905515.html