package Devmanuals.com; import java.util.List; import java.util.ArrayList; public class ListHashCode { public static void main (String args []){ List l1= new ArrayList(); l1.add("Ram"); l1.add("is"); l1.add("a"); l1.add("boy"); System.out.println("The Element of list1 is : "+l1); System.out.println("The size of list1 is : "+l1.size()); List l2=new ArrayList(); l2.add("Ram"); l2.add("is"); l2.add("a"); l2.add("boy"); System.out.println("The Element of list2 is : "+l2); System.out.println("The size of list2 is : "+l2.size()); l1.equals(l2); System.out.println("The Elements are equal : "+l1.equals(l2)); //When all the elements are equal then hash code is equal System.out.println("The id of the list1 = "+l1.hashCode()); System.out.println("The id of the list2 = "+l2.hashCode()); System.out.println("The id of Zero position of the list1 = "+l1.get(0).hashCode()); System.out.println("The id of Zero position of the list1 = "+l2.get(0).hashCode()); List l3=new ArrayList(); l3.add("Ram"); l3.add("boy"); System.out.println("The elements of list3 is : "+l3); System.out.println("The size of list3 is : "+l3.size()); List l4=new ArrayList(); l4.add("Ram"); l4.add("a"); System.out.println("The element of list4 is : "+l4); System.out.println("The size of list4 is : "+l4.size()); System.out.println("The Elements are equal : "+l3.equals(l4)); //When all elements are not equal then hash code is different for different list Object System.out.println("The id of the list3 = "+l3.hashCode()); System.out.println("The id of the list4 = "+l4.hashCode()); } }