import java.util.ArrayList;
class HashingTest
{
public static void main(String a[])
{
ArrayList ar=new ArrayList();
ArrayList ar2=new ArrayList();
ar.add(4);
ar.add(5);
ar.add(6);
ar2.add(4);
ar2.add(5);
ar2.add(6);
System.out.println("Value of ar[0] is "+ar.get(0)+ " & hashcode
is"+ar.hashCode());
System.out.print("Value of ar2[0] is "+ar2.get(0)+ " & hashcode
is"+ar2.hashCode());
}
}
Output :-
Value of ar[0] is 4 & hashcode is33796
Value of ar2[0] is 4 & hashcode is33796
In the above program, i have created 2 instances of class ArrayList as "ar & ar2".
By hashing theory, no two different instances have similar hashcode. but when i run this program i got same output for both instances .Got confused :-( ...
Can Anyone put some light on this ?