List<Map<String, String>> 开启 Map<String, List<String>>
将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>>的更多相关文章
- No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, org.springframework.boot.logging.LogLevel>]
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...
- No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...
- 为什么Java中的String是设计成不可变的?(Why String is immutable in java)
There are many reasons due to the string class has been made immutable in Java. These reasons in vie ...
- String 类的实现(3)引用计数实现String类
我们知道在C++中动态开辟空间时是用字符new和delete的.其中使用new test[N]方式开辟空间时实际上是开辟了(N*sizeof(test)+4)字节的空间.如图示其中保存N的值主要用于析 ...
- java 中String类的常用方法总结,带你玩转String类。
String类: String类在java.lang包中,java使用String类创建一个字符串变量,字符串变量属于对象.String类对象创建后不能修改,StringBuffer & St ...
- String放入运行时常量池的时机与String.intern()方法解惑
运行时常量池概述 Java运行时常量池中主要存放两大类常量:字面量和符号引用.字面量比较接近于Java语言层面的常量概念,如文本字符串.声明为final的常量值等. 而符号引用则属于编译原理方面的概念 ...
- List<String> list=new ArrayList<String>(20);为什么要声明为List 而不是ArrayList<String>?
如何理解:List<String> list=new ArrayList<String>();为甚麼要声明为List 而不是ArrayList<String>? 在 ...
- 使用HashMap须要注意的事儿:不要暴露Map.entry给外部不可信代码Map.entrySet()
Map/HashMap是java中一种非经常常使用的数据结构,一般我们在应用中做的事情就是调用put向容器写入数据或者是get从容器读取数据. Map.entrySet()这种方法返回了键值对的集合, ...
- JavaBean转化为Map,List<JavaBean>转化为List<Map>
/** * 将对象转化为map * * @param bean * @param <T> * @return */ private <T> Map<String, Obj ...
- Java的map键值对的用法,map的遍历,Entry对象的使用
思路: 1.定义集合 2.存储数据 3.添加元素 4.遍历 4.1将需要遍历的集合的键封装到set集合中(这用到了entrySet方法,和Entry对象) 4.2声明迭代器或者用for增强循环 4.3 ...
随机推荐
- Codeforces Round #460 (Div. 2) E. Congruence Equation (CRT+数论)
题目链接: http://codeforces.com/problemset/problem/919/E 题意: 让你求满足 \(na^n\equiv b \pmod p\) 的 \(n\) 的个数. ...
- 微服务实战(四):服务发现的可行方案以及实践案例 - DockOne.io
原文:微服务实战(四):服务发现的可行方案以及实践案例 - DockOne.io 这是关于使用微服务架构创建应用系列的第四篇文章.第一篇介绍了微服务架构的模式,讨论了使用微服务架构的优缺点.第二和第三 ...
- Java基础学习总结(49)——Excel导入导出工具类
在项目的pom文件中引入 <dependency> <groupId>net.sourceforge.jexcelapi</groupId> <artifac ...
- IDEACould not autowire. No beans of 'xxxMapper' type found.
作为一名刚开始使用idea的新手,最近在使用maven+springMVC框架时遇到了这样一个问题:Could not autowire. No beans of 'xxxMapper' type f ...
- struts2--笔记(一)
1.什么是struts2? 框架是一些已经写好的代码,一般情况下于产品是无关的,可以提高效率. 2.javaEE的三层结构:表现层.业务层.持久层组成,struts是变现层的一个框架结构,分成结构的方 ...
- oracle高效分页存储过程(百万数据级)
create or replace procedure Pager( page in number,--数据页数,从1开始 pageSize in number,--每页大小 tableName nv ...
- android闹钟实现原理
闹钟的原理可用下面我自己画的一幅图来概括:(不对的地方,尽管吐槽) 我们来看看新建闹钟到闹钟响铃的步骤: 1.新建一个闹钟: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
- POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列
POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...
- ocx 中使用CImage和CComPtr
#include <atlimage.h> using namespace ATL;
- LeetCode解题报告--2Sum, 3Sum, 4Sum, K Sum求和问题总结
前言: 这几天在做LeetCode 里面有2sum, 3sum(closest), 4sum等问题, 这类问题是典型的递归思路解题.该这类问题的关键在于,在进行求和求解前,要先排序Arrays.sor ...