The hashCode() method of java.util.AbstractList class is used to return the hash code value for this list.
Syntax:
public int hashCode()
Returns Value: This method returns the hash code value for this list.
Below are the examples to illustrate the hashCode() method.
Example 1:
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
try {
AbstractList<Integer>
arrlist1 = new ArrayList<Integer>();
arrlist1.add( 10 );
arrlist1.add( 20 );
arrlist1.add( 30 );
arrlist1.add( 40 );
arrlist1.add( 50 );
System.out.println( "ArrayListlist : " + arrlist1);
int code = arrlist1.hashCode();
System.out.println( "HashCode : " + code);
}
catch (IndexOutOfBoundsException e) {
System.out.println( "Exception thrown : " + e);
}
}
}
|
Output:
ArrayListlist : [10, 20, 30, 40, 50]
HashCode : 38490301
Example 2:
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
try {
AbstractList<String>
arrlist1 = new ArrayList<String>();
arrlist1.add( "A" );
arrlist1.add( "B" );
arrlist1.add( "C" );
arrlist1.add( "D" );
arrlist1.add( "E" );
System.out.println( "ArrayListlist : "
+ arrlist1);
int code = arrlist1.hashCode();
System.out.println( "HashCode : " + code);
}
catch (IndexOutOfBoundsException e) {
System.out.println( "Exception thrown : " + e);
}
}
}
|
Output:
ArrayListlist : [A, B, C, D, E]
HashCode : 90690786