Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: May 5, 2021 4:40 PM
Views: 472
Tags: collections
  1.    public static void main(String[] args) {
  2.  
  3.         var hash_map= new HashMap<Integer,String>();
  4.  
  5.         //Werte zuweisen mit PUT anstatt mit ADD!!
  6.         hash_map.put(1, "Red");
  7.         hash_map.put(2, "Green");
  8.         hash_map.put(3, "Black");
  9.         hash_map.put(4, "White");
  10.         hash_map.put(5, "Blue");
  11.  
  12.         var hash_map2 = new HashMap<Integer, String>();
  13.         hash_map2.put(4, "White");
  14.         hash_map2.put(5, "Blue");
  15.         hash_map2.put(6, "Orange");
  16.  
  17.         System.out.println("Vorher: " + hash_map2);
  18.         //von hash_map zu hash_map2 kopieren und einfügen mit putAll!!
  19.         hash_map2.putAll(hash_map);
  20.         System.out.println("Werte in zweiter Map: " + hash_map2);
  21.  
  22.     }
  23. }