<<< Common methods of the HashMap and TreeMap classes | Index | Code that uses a tree map >>> |
// create an empty hash map HashMap<String,String> books = new HashMap<>(); // add three entries books.put("wooz", "Wizard of Oz"); books.put("mbdk", "Moby Dick"); books.put("wuth", "Wuthering Heights"); // print the entries for (Map.Entry book : books.entrySet()) System.out.println(book.getKey() + ": " + book.getValue()); // print the entry whose key is "mbdk" System.out.println("\nCode mbdk is " + books.get("mbdk"));
Resulting output for code that uses a hash map
wuth: Wuthering Heights mbdk: Moby Dick wooz: Wizard of Oz Code mbdk is Moby Dick
<<< Common methods of the HashMap and TreeMap classes | Index | Code that uses a tree map >>> |