AbstractList hashCode() method in Java with Examples
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:
// Java program to demonstrate // hashCode() method // for Integer value import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // Creating object of AbstractList<Integer> AbstractList<Integer> arrlist1 = new ArrayList<Integer>(); // Populating arrlist1 arrlist1.add(10); arrlist1.add(20); arrlist1.add(30); arrlist1.add(40); arrlist1.add(50); // print arrlist1 System.out.println("ArrayListlist : " + arrlist1); // getting the value at the index 3 // using get() method int code = arrlist1.hashCode(); // print the value System.out.println("HashCode : " + code); } catch (IndexOutOfBoundsException e) { System.out.println("Exception thrown : " + e); } } } |
chevron_right
filter_none
Output:
ArrayListlist : [10, 20, 30, 40, 50] HashCode : 38490301
Example 2:
// Java program to demonstrate // hashCode() method // for String value import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // Creating object of AbstractList<String> AbstractList<String> arrlist1 = new ArrayList<String>(); // Populating arrlist1 arrlist1.add("A"); arrlist1.add("B"); arrlist1.add("C"); arrlist1.add("D"); arrlist1.add("E"); // print arrlist1 System.out.println("ArrayListlist : " + arrlist1); // getting the value at the index 3 // using get() method int code = arrlist1.hashCode(); // print the value System.out.println("HashCode : " + code); } catch (IndexOutOfBoundsException e) { System.out.println("Exception thrown : " + e); } } } |
chevron_right
filter_none
Output:
ArrayListlist : [A, B, C, D, E] HashCode : 90690786
Recommended Posts:
- AbstractList get() method in Java with Examples
- AbstractList set() Method in Java with Examples
- AbstractList add(E ele) method in Java with Examples
- AbstractList equals() method in Java with Examples
- AbstractList iterator() method in Java with Examples
- AbstractList clear() method in Java with Examples
- AbstractList lastIndexOf() method in Java with Examples
- AbstractList listIterator() Method in Java with Examples
- AbstractList indexOf() method in Java with Examples
- AbstractList remove() Method in Java with Examples
- AbstractList subList() method in Java with Examples
- AbstractList addAll() method in Java with Examples
- AbstractList add(int index, E element) method in Java with Examples
- Set hashCode() method in Java with Examples
- Map hashCode() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

