package devmanuals.com; import java.util.Map; import java.util.HashMap; import java.util.TreeMap; public class MapHashCode { public static void main(String args[]) { Map mp1 = new HashMap(); mp1.put(1, "A"); mp1.put(2, "B"); mp1.put(3, "C"); mp1.put(4, "D"); System.out.println("Mapping1 = " + mp1); System.out.println("Size of map1 = " + mp1.size()); Map mp2 = new TreeMap(); mp2.put(1, "A"); mp2.put(2, "B"); mp2.put(3, "C"); mp2.put(4, "D"); System.out.println("Mapping2 = " + mp2); System.out.println("Size of map2 = " + mp2.size()); boolean bol = mp1.equals(mp2); System.out.println("Is the elements of map1 and map2 are equal : " + bol); System.out.println("Hash code of map1 = " + mp1.hashCode()); System.out.println("Hash code of map2 = " + mp2.hashCode()); Map mp3 = new HashMap(); mp3.put(1, "E"); mp3.put(2, "F"); mp3.put(3, "G"); mp3.put(4, "H"); System.out.println("Mapping3 = " + mp3); System.out.println("Size of map3 = " + mp3.size()); System.out.println("Mapping1 = " + mp1); boolean bol1 = mp1.equals(mp3); System.out.println("Is the elements of map1 and map3 are equal : " + bol1); System.out.println("Hash code of map1 = " + mp1.hashCode()); System.out.println("Hash code of map3 = " + mp3.hashCode()); System.out.println("Mapping2 = " + mp2); System.out.println("Mapping3 = " + mp3); boolean bol2 = mp2.equals(mp3); System.out.println("Is the elements of map2 and map3 are equal : " + bol2); System.out.println("Hash code of map2 = " + mp2.hashCode()); System.out.println("Hash code of map3 = " + mp3.hashCode()); } }