如何将arraylist更改为hashmap对象?

时间:2015-12-14 12:32:09

标签: json hashmap

Gson gson = new Gson();
HashMap<String, BeanClass> hm = new HashMap<>();
hm.put("First", beanclass1);
hm.put("Second", beanclass2);
hm.put("Third", beanclass3);
hm.put("Fourth", beanclass4);
hm.put("Fifth", beanclass5);

ArrayList al = new ArrayList();
al.add(hm);

String st = gson.toJson(al);
System.out.println(st);

ArrayList al2 = gson.fromJson(st, ArrayList.class);

System.out.println(al2);

//  HashMap hm1= (HashMap) al2.get(0);

 // System.out.println(hm1);

如何将arraylist转换为hashmap?这里的hm是hashmap。然后       转换为arraylist(al)。然后al转换为al2 arrayobject。最后,如何将al2 arrayobject转换为hashmap对象?

error:Exception in thread "main" java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to java.util.HashMap

0 个答案:

没有答案