Ivan18113

HashMap_Class

Apr 5th, 2021
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. package Hashing;
  2.  
  3. import java.util.*;
  4.  
  5. public class HashMap_Class {
  6.     public static void main(String[] args) {
  7.         HashMap<String, Double> MyDictionary = new HashMap<String, Double>(16);
  8.  
  9.         MyDictionary.put("Strahil",3.00);
  10.         MyDictionary.put("Sasho", 5.00);
  11.         MyDictionary.put("Ivan", 6.00);
  12.  
  13.         for (Map.Entry< String, Double> items : MyDictionary.entrySet()){
  14.             System.out.printf( " Student %s has %.2f%n" , items.getKey(), items.getValue());
  15.         }
  16.         //REMOVE
  17.         MyDictionary.remove("Strahil");
  18.         System.out.println("Strahil removed.");
  19.  
  20.         //CONTAINS KEY
  21.         System.out.printf("Is Strahil in the hash table: %b %n", MyDictionary.containsKey("Strahil"));
  22.         //CONTAINS VALUE
  23.         System.out.printf("Is Strahil in the hash table: %b %n", MyDictionary.containsValue(3.00));
  24.  
  25.         System.out.println("Student and marks:");
  26.  
  27.         //FOR-EACH-CYCLE :::::::::::::::: HASH-MAP
  28.         //PRINT KEYS AND VALUES BY MAP.ENTRY() METHOD
  29.  
  30.         for (Map.Entry< String, Double> items : MyDictionary.entrySet()){
  31.             System.out.printf( " Student %s has %.2f%n" , items.getKey(), items.getValue());
  32.         }
  33.     }//end of main
  34. }//end of class
Advertisement
Add Comment
Please, Sign In to add comment