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 ...
随机推荐
- Android Material风格的应用(五)--CollapsingToolbar
Collapsing Toolbar Android Material风格的应用(一)--AppBar TabLayoutAndroid Material风格的应用(二)--RecyclerViewA ...
- solrcloud集群搭建
solrcloud 集群搭建 初始条件: 1. 三台服务器 IP 地址分别为 192.168.1.133 192.168.1.134 192.168.1.135 2. 使用 solr-5.3.1,zo ...
- Redo current损坏
如果损坏的是current redo log (select group#,sequence#,archived,status from v$log;) 有两种情况: A. 数据库是正常关闭 ...
- JMeter--聚合报告之 90% Line 正确理解
90% Line 参数正确的含义: 虽然,我的上面理解有一定的道理,显然它(90% 用户的响应时间)是错误的.那看看JMeter 官网是怎么说的? 90% Line - 90% of the samp ...
- Linux下开启关闭防火墙
一.Linux下开启/关闭防火墙命令 1) 永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重 ...
- Log Explorer 使用说明(原创)
关于Log Explorer (我抄的) 介绍Log Explorer主要用于对MSSQLServer的事物分析和数据恢复.你可以浏览日志.导出数据.恢复被修改或者删除的数据(包括执行过update, ...
- Iaas、Paas和Saas的区别
Iaas: Infrastructure-as-a-service(基础设施即服务),Iaas上购买的一般是主机,用户不光要开发程序,还要考虑搭建系统,维护运行环境,以及怎么容灾,怎么做到高可用,怎么 ...
- Nutch关于robot.txt的处理 分类: H3_NUTCH 2015-01-28 11:20 472人阅读 评论(0) 收藏
在nutch中,默认情况下尊重robot.txt的配置,同时不提供配置项以忽略robot.txt. 以下是其中一个解释.即作为apache的一个开源项目,必须遵循某些规定,同时由于开放了源代码,可以简 ...
- sublime课程3 sublime编辑器的常用设置有哪些
sublime课程3 sublime编辑器的常用设置有哪些 一.总结 一句话总结:其实功能的话可以直接取配置里面搜索关键词,所以搜索是神技. 1.sublime如何开启背景线? "highl ...
- PWA之Web 应用清单
原文 简书原文:https://www.jianshu.com/p/5c96242188e8 大纲 1.什么是Web 应用清单 2.“清单文件”:Web App Manifest 规范的应用 3.we ...