Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: May 5, 2021 4:52 PM
Views: 499
Tags: collections
  1.     public static void main(String[] args) {
  2.  
  3.         var hash_map= new HashMap<String, Integer>();
  4.  
  5.         //Werte zuweisen mit PUT anstatt mit ADD!!
  6.         hash_map.put("Red", 1);
  7.         hash_map.put("Green", 2);
  8.         hash_map.put("Black", 3);
  9.         hash_map.put("White", 4);
  10.         hash_map.put("Blue", 5);
  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_map);
  18.  
  19.         System.out.println("Does the Key 'Green' exist?");
  20.  
  21.         if(hash_map.containsKey("Green")){
  22.             System.out.println("Yes! - " + hash_map.get("Green"));
  23.  
  24.         }else{
  25.             System.out.println("No!");
  26.         }
  27.     }
  28. }
  29.