我有这段代码,
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
?我怎样才能做到这一点?非常感谢你
答案 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等来初始化它