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 ...
随机推荐
- MySQL和Python交互
与Python交互 python3模块名:pymysql conda install pymysql conda install sqlalchemy python2模块名:MySQLdb impor ...
- php中嵌套html代码和html代码中嵌套php方式
php中嵌套html代码和html代码中嵌套php方式 一.总结 拷贝的话直接html代码是极好的方式 1.php中嵌套html代码(本质是原生php):a.原生嵌套<?php .....?&g ...
- TensorFlow 学习(十五)—— tensorflow.python.platform
tensorflow.python.platform 下的常用工具类和工具函数:tensorflow/tensorflow/python/platform at master · tensorflow ...
- 用CSS实现阴阳八卦图等图形
CSS还是比较强大的,可以实现中国古典的"阴阳八卦图"等形状. 正方形 #rectangle { width: 200px; height: 100px; backgrount-c ...
- [Err] 1136 - Column count doesn't match value count at row 1
1 错误描写叙述 [Err] 1136 - Column count doesn't match value count at row 1 Procedure execution failed 113 ...
- ANDROID内存优化(大汇总——全)
写在最前: 本文的思路主要借鉴了2014年AnDevCon开发者大会的一个演讲PPT,加上把网上搜集的各种内存零散知识点进行汇总.挑选.简化后整理而成. 所以我将本文定义为一个工具类的文章,如果你在A ...
- vim修复,telnet安装启动,linux更新软件源
vim修复: 修复前提,你到UBUNTU能够联网.否则仅仅能卸载,不能安装 1.sudo apt-get remove vim-common 2.sudo apt-get install vim ...
- Android自定义组件系列【9】——Canvas绘制折线图
有时候我们在项目中会遇到使用折线图等图形,Android的开源项目中为我们提供了很多插件,但是很多时候我们需要根据具体项目自定义这些图表,这一篇文章我们一起来看看如何在Android中使用Canvas ...
- thinkphp3.2.3 小程序获取手机号 php 解密
首先是把这个文件夹放到\ThinkPHP\Library\Org里面 //zll 根据加密字符串和session_key和iv获取手机号 /** * [getphone description] * ...
- 枚举系统磁盘驱动器(使用GetLogicalDriveStrings API函数,system("pause"); 很实用,还用到wcslen等函数)
代码如下: #include "stdafx.h" #include <vector> #include <string> #include <Win ...