Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Hashing;
- import java.util.*;
- public class HashMap_Class {
- public static void main(String[] args) {
- HashMap<String, Double> MyDictionary = new HashMap<String, Double>(16);
- MyDictionary.put("Strahil",3.00);
- MyDictionary.put("Sasho", 5.00);
- MyDictionary.put("Ivan", 6.00);
- for (Map.Entry< String, Double> items : MyDictionary.entrySet()){
- System.out.printf( " Student %s has %.2f%n" , items.getKey(), items.getValue());
- }
- //REMOVE
- MyDictionary.remove("Strahil");
- System.out.println("Strahil removed.");
- //CONTAINS KEY
- System.out.printf("Is Strahil in the hash table: %b %n", MyDictionary.containsKey("Strahil"));
- //CONTAINS VALUE
- System.out.printf("Is Strahil in the hash table: %b %n", MyDictionary.containsValue(3.00));
- System.out.println("Student and marks:");
- //FOR-EACH-CYCLE :::::::::::::::: HASH-MAP
- //PRINT KEYS AND VALUES BY MAP.ENTRY() METHOD
- for (Map.Entry< String, Double> items : MyDictionary.entrySet()){
- System.out.printf( " Student %s has %.2f%n" , items.getKey(), items.getValue());
- }
- }//end of main
- }//end of class
Advertisement
Add Comment
Please, Sign In to add comment