fork download
  1. import java.util.*;
  2. import java.util.Map.Entry;
  3.  
  4. class Test
  5. {
  6. public static void main(String[] args)
  7. {
  8. HashMap<String,Integer> map = new HashMap<String,Integer>();
  9. map.put("One",1);
  10. map.put("Two",2);
  11. map.put("Three",3);
  12. map.put("Four",4);
  13. System.out.println(map);
  14. Set<Entry<String,Integer>> s=map.entrySet();
  15. for(Entry<String,Integer> ent:s) {
  16. System.out.println(ent.getKey()+"..."+ent.getValue());
  17. }
  18. System.out.println();
  19. HashMap<String,Integer> map2=new HashMap<String,Integer>();
  20. map2.put("Five",5);
  21. map2.put("Six",6);
  22. map2.putAll(map);
  23. System.out.println(map2);
  24. Set<Entry<String,Integer>> s2=map2.entrySet();
  25. for(Entry<String,Integer> ent2:s2) {
  26. System.out.println(ent2.getKey()+"..."+ent2.getValue());
  27. }
  28. }
  29. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
{One=1, Four=4, Two=2, Three=3}
One...1
Four...4
Two...2
Three...3

{Five=5, Six=6, One=1, Four=4, Two=2, Three=3}
Five...5
Six...6
One...1
Four...4
Two...2
Three...3