Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class upr17 {
- public static void main(String[] args) {
- HashMap<String, Double> MyDictionary = new HashMap<String, Double>(10);
- MyDictionary.put("Иван", 3.50);
- MyDictionary.put("Ивайло", 5.50);
- MyDictionary.put("Джан", 6.00);
- MyDictionary.put("Мария", 5.00);
- MyDictionary.put("Никол",4.50);
- System.out.println(MyDictionary);
- //size
- System.out.println("MyDict size: = " + MyDictionary.size());
- //get by key
- System.out.printf("The Mark of Джан is : %.2f%n", MyDictionary.get("Джан"));
- //modify
- System.out.printf("Before the mark of Maria is : %.2f %n", MyDictionary.get("Мария"));
- MyDictionary.put("Мария", 5.00);
- System.out.printf("After the mark of Maria is : %.2f %n", MyDictionary.get("Мария"));
- //remove
- MyDictionary.remove("Иван");
- System.out.println("Иван is removed !");
- System.out.println("After removing " + MyDictionary);
- System.out.println("MyDict sieze after removing = " + MyDictionary.size());
- //search by key and by value - result is boolean
- System.out.println("Do we have Джан: " + MyDictionary.containsKey("Джан"));
- System.out.println("Do we have Иван: " + MyDictionary.containsKey("Иван"));
- System.out.println("Do we have 6.00: " + MyDictionary.containsValue(6.00));
- //(entry set)
- //for-each by entry set get-key and get-value
- for (Map.Entry<String, Double> items: MyDictionary.entrySet() ){
- System.out.printf("Person : %s has mark of : %.2f %n", items.getKey(), items.getValue());
- }
- //other
- System.out.println("MyHashMap entrySet: " + MyDictionary.entrySet());
- System.out.println("MyHashMap hashCode: " + MyDictionary.hashCode());
- System.out.println("MyHashMap getClass: " + MyDictionary.getClass());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement