Open In App

AbstractSequentialList get() method in Java with Examples

Last Updated : 26 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The get() method of AbstractSequentialList is used to fetch or retrieve an element at a specific index from a AbstractSequentialList. Syntax:
AbstractSequentialList.get(int index)
Parameters: The parameter index is of integer data type that specifies the position or index of the element to be fetched from the AbstractSequentialList. Return Value: The method returns the element present at the position specified by the parameter index. Below programs illustrate the Java.util.AbstractSequentialList.get() method: Example 1: Java
// Java code to illustrate get() method

import java.util.*;
import java.util.AbstractSequentialList;

public class AbstractSequentialListDemo {
    public static void main(String args[])
    {

        // Creating an empty AbstractSequentialList
        AbstractSequentialList<String>
            absqlist = new LinkedList<String>();

        // Use add() method to add elements
        absqlist.add("Geeks");
        absqlist.add("for");
        absqlist.add("Geeks");
        absqlist.add("10");
        absqlist.add("20");

        // Displaying the list
        System.out.println("AbstractSequentialList:"
                           + absqlist);

        // Fetching the specific element from the list
        System.out.println("The element is: "
                           + absqlist.get(2));
    }
}
Output:
AbstractSequentialList:[Geeks, for, Geeks, 10, 20]
The element is: Geeks
Example 2: Java
// Java code to illustrate get() method

import java.util.*;
import java.util.AbstractSequentialList;

public class AbstractSequentialListDemo {
    public static void main(String args[])
    {

        // Creating an empty AbstractSequentialList
        AbstractSequentialList<Integer>
            absqlist = new LinkedList<Integer>();

        // Use add() method to add elements
        absqlist.add(1);
        absqlist.add(2);
        absqlist.add(3);
        absqlist.add(4);
        absqlist.add(5);

        // Displaying the list
        System.out.println("AbstractSequentialList:"
                           + absqlist);

        // Fetching the specific element from the list
        System.out.println("The element is: "
                           + absqlist.get(4));
    }
}
Output:
AbstractSequentialList:[1, 2, 3, 4, 5]
The element is: 5

Next Article

Similar Reads