The hashCode() method of AbstractList class in Java



The hashCode() method of AbstractList class returns the hash code value for this list.

The syntax is as follows:

public int hashCode()

To work with the AbstractList class, import the following package:

import java.util.AbstractList;

The following is an example to implement hashCode() method of the AbstractlList class in Java:

Example

 Live Demo

import java.util.ArrayList;
import java.util.AbstractList;
public class Demo {
   public static void main(String[] args) {
      AbstractList<Integer> myList = new ArrayList<Integer>();
      myList.add(50);
      myList.add(100);
      myList.add(150);
      myList.add(200);
      myList.add(250);
      myList.add(300);
      myList.add(350);
      myList.add(400);
      System.out.println("Elements in the AbstractList class = " + myList);
      System.out.println("HashCode = " + myList.hashCode());
   }
}

Output

Elements in the AbstractList class = [50, 100, 150, 200, 250, 300, 350, 400]
HashCode = -1818371895

Advertisements