The get() method of AbstractList class in Java

Java 8Object Oriented ProgrammingProgramming

The get() method of the AbstractList class is used to get the element at the specified position in the list. It returns the element at the position set as parameter.

The syntax is as follows:

public abstract E get(int index)

Here, index is the index of the element to return.

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

import java.util.AbstractList;

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

Example

import java.util.LinkedList;
import java.util.AbstractList;
public class Demo {
   public static void main(String[] args) {
      AbstractList<Integer> myList = new LinkedList<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("Element at index 5 = " + myList.get(5));
   }
}

Output

Elements in the AbstractList class = [50, 100, 150, 200, 250, 300, 350, 400]
Element at index 5 = 300
raja
Published on 02-Apr-2019 11:46:52
Advertisements