Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- public class HashMapClassWork {
- public static void main(String[] args) {
- HashMap<String, Double> MyDictionary = new HashMap<String, Double>();
- MyDictionary.put("Ivan", 3.00);
- MyDictionary.put("Georgi", 4.50);
- MyDictionary.put("Dimitur", 5.50);
- MyDictionary.put("Veselin", 3.50);
- MyDictionary.put("Canislav", 4.00);
- MyDictionary.put("Nikol", 6.00);
- System.out.println("HashMap Size:" + MyDictionary.size());
- Double TsanevMark = MyDictionary.get("Canislav");
- System.out.printf("Canislav's mark: %.2f %n", TsanevMark);
- MyDictionary.remove("Canislav");
- System.out.println("Canislav removed.");
- System.out.printf("Is Canislav in the HashTable: %b %n", MyDictionary.containsKey("Canislav"));
- System.out.printf("Is Canislav in the HashTable: %b %n", MyDictionary.containsValue(6.00));
- MyDictionary.put("Nikol", 3.25);
- System.out.println("Nikol's mark changed");
- System.out.println("Students and marks: ");
- System.out.println(MyDictionary);
- for (Map.Entry<String, Double>items : MyDictionary.entrySet()) {
- if(items.getKey().equals("Dimitur")){
- System.out.printf("Mark of %s is %.2f", items.getKey(), items.getValue());
- }
- System.out.printf("Student %s has %.2f%n",items.getKey(), items.getValue());
- }
- System.out.printf("There are %d students.%n", MyDictionary.size());
- MyDictionary.clear();
- System.out.println("Students Dictionary (By hashmap) cleared.");
- System.out.printf("Is hashtable empty: %b%n", MyDictionary.isEmpty());
- }
- }
Add Comment
Please, Sign In to add comment