lamiastella

hashmap test

Mar 2nd, 2016
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. /**
  5.  * Created by mona on 3/2/16.
  6.  */
  7. public class HashMapTest {
  8.     static HashMap<String, Boolean> map=new HashMap<>();
  9.     public static void main(String[] args) {
  10.         map.put("Mona", true);
  11.         map.put("Mina", false);
  12.         map.put("Hassan", true);
  13.         map.put("Amir", false);
  14.         System.out.println(map.get("Mina"));
  15.         if (map.containsKey("Jack")) {
  16.             System.out.println("Jack is here");
  17.         }
  18.         if (map.containsValue(false)) {
  19.             System.out.println("hashmap has false values");
  20.         }
  21.  
  22.         for (String s : map.keySet()) {
  23.             System.out.println(map.get(s));
  24.         }
  25. /*      how to get the entries from map
  26.         for (Boolean b : map.values()){
  27.             System.out.println(map.get(b));
  28.         }
  29.  
  30.  
  31.  
  32.  
  33. */
  34.         for (Map.Entry kv : map.entrySet()) {
  35.             map.remove("Mona");
  36.         }
  37.  
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment