How can I store HashMaplt;String, ArrayListlt;Stringgt;gt; inside a list?(如何存储 HashMaplt;String, ArrayListlt;Stringgt;gt;在列表中?)
问题描述
我的 hashmap 将字符串存储为键,将数组列表存储为值.现在,我需要将其嵌入到列表中.也就是说,它将具有以下形式:
My hashmap stores the string as key and arraylist as the values. Now, I need to embed this into a list. That is, it will be of the following form:
List<HashMap<String, ArrayList<String>>>
这些是我使用的声明:
Map<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
ArrayList<String> arraylist = new ArrayList<String>();
map.put(key,arraylist);
List<String> list = new ArrayList<String>();
谁能帮我在列表中使用哪种方法以及如何继续将我的地图存储到其中?
Can anyone help me which method and how to use in the list to proceed storing my map into it?
推荐答案
总是尝试在 Collection 中使用接口引用,这增加了更多的灵活性.
下面的代码有什么问题?
Always try to use interface reference in Collection, this adds more flexibility.
What is the problem with the below code?
List<Map<String,List<String>>> list = new ArrayList<Map<String,List<String>>>();//This is the final list you need
Map<String, List<String>> map1 = new HashMap<String, List<String>>();//This is one instance of the map you want to store in the above list.
List<String> arraylist1 = new ArrayList<String>();
arraylist1.add("Text1");//And so on..
map1.put("key1",arraylist1);
//And so on...
list.add(map1);//In this way you can add.
你可以像上面那样轻松地做到这一点.
You can easily do it like the above.
这篇关于如何存储 HashMap<String, ArrayList<String>>在列表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何存储 HashMap<String, ArrayList<String>>在列表中?


基础教程推荐
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01