import java.util.*; public class HashMapDemo { public static void main(String[] args) { // Create a map and put some items into it Map months = new HashMap(); months.put("September", 30); months.put("July", 31); months.put("January", 31); months.put("May",31); months.put("November", 30); // List all the items in the map for(String month : months.keySet()) { System.out.println(month + " : " + months.get(month) ); } // Alternate technique // for( Map.Entry item: months.entrySet()) // { // System.out.println(item.getKey() + " : " + item.getValue() ); // } System.out.println("Contains May? " + months.containsKey("May")); System.out.println("Contains ABC? " + months.containsKey("ABC")); System.out.println("Value of July? " + months.get("July")); months.put("May", 3); System.out.println("Value of May? " + months.get("May")); } } /* January : 31 November : 30 May : 30 July : 31 September : 30 Contains May? true Contains ABC? false Value of July? 31 Value of May? 3 */