fork download
  1. import java.util.*;
  2.  
  3. class Main{
  4. public static void main(String args[]) {
  5. sample1();
  6. sample2();
  7. }
  8. static void sample1() {
  9. ArrayList<HashMap<String, String>> arrayMap = new ArrayList<HashMap<String, String>>();
  10. HashMap<String, String>map = new HashMap<String, String>();
  11.  
  12. map.put("key0", "value0");
  13. arrayMap.add(0, map);
  14. map.put("key1", "value1");
  15. arrayMap.add(1, map);
  16.  
  17. System.out.println("sample1:");
  18. System.out.println(arrayMap.get(0).get("key0"));
  19. System.out.println(arrayMap.get(1).get("key1"));
  20. System.out.println(arrayMap.get(1).get("key0"));
  21. }
  22. static void sample2() {
  23. ArrayList<HashMap<String, String>> arrayMap = new ArrayList<HashMap<String, String>>();
  24. HashMap<String, String>map1 = new HashMap<String, String>();
  25. HashMap<String, String>map2 = new HashMap<String, String>();
  26.  
  27. map1.put("key", "value0");
  28. arrayMap.add(0, map1);
  29. map2.put("key", "value1");
  30. arrayMap.add(1, map2);
  31.  
  32. System.out.println("sample2:");
  33. System.out.println(arrayMap.get(0).get("key"));
  34. System.out.println(arrayMap.get(1).get("key"));
  35. }
  36. }
  37. /* end */
  38.  
  39.  
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
sample1:
value0
value1
value0
sample2:
value0
value1