将HashMap <string,string =“”>转换为HashMap <string,list <string =“”>&gt;()</string,> </string,>

时间:2014-11-29 16:12:59

标签: java android android-listview hashmap

我有这段代码,

ArrayList<HashMap<String, String>> eventosList;

     HashMap<String, String> contact = new HashMap<String, String>();

                            contact.put("id", id);
                            contact.put("name", name);

eventosList.add(contact);

是否可以将此HashMap<String, String> contact转换为HashMap<String, List<String>>() contact?我怎样才能做到这一点?非常感谢你

2 个答案:

答案 0 :(得分:0)

这个怎么样?

    ArrayList<HashMap<String, List<String>>> eventosList = new ArrayList<HashMap<String, List<String>>>();

    HashMap<String, List<String>> contact = new HashMap<String, List<String>>();
    contact.put("id", list1);
    contact.put("name", list2);

    eventosList.add(contact);

答案 1 :(得分:0)

试试这样:

ArrayList<HashMap<String, List<String>>> eventosList = new ArrayList<HashMap<String, List<String>>>();
HashMap<String, List<String>> contact = new HashMap<String, List<String>>();

List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
contact.put("id", list);
List<String> list1 = new ArrayList<String>();
list1.add("Mohammed");
list1.add("Ali");
contact.put("name", list1);
eventosList.add(contact);

同样注意给定here:List是一个INTERFACE,你不能初始化一个接口,所以使用它的任何实现类,如Arraylist,Vector,LinkedList,AbstractList,AbstractSequentialList,AttributeList等来初始化它