Tuesday, November 6, 2012

hashCode in Java

import java.util.ArrayList;
public class hashCode {

    public static void main(String[] args) {

        ArrayList a1 = new ArrayList();
        a1.add("One");
        a1.add("Two");
        a1.add("Three");
       
        int hashCodeforInvokingCollection = 0;
        for(int i=0;i<a1.size();i++)
        {
            //hashCodeforInvokingCollection = a1.get(i).hashCode();
            hashCodeforInvokingCollection = a1.get(i).hashCode();
            System.out.println(" a1's "+a1.get(i)+" " +hashCodeforInvokingCollection);
        }       
       
    }
}

Answer
----------
a1's One 79430
a1's Two 84524
a1's Three 80786814

No comments:

Post a Comment