如何储存HashMap< String,ArrayList< String>>在列表里面? [英] How can I store HashMap<String, ArrayList<String>> inside a list?

查看:301
本文介绍了如何储存HashMap< String,ArrayList< String>>在列表里面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的hashmap将字符串存储为键,并将arraylist存储为值。现在,我需要将其嵌入到列表中。

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>>>

这些是我用过的声明:

These are the declarations I have used:

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&lt; String,ArrayList&lt; String&gt;&gt;在列表里面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆