AbstractSequentialList get() method in Java with Examples

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

AbstractSequentialList:[Geeks, for, Geeks, 10, 20]
The element is: Geeks

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

AbstractSequentialList:[1, 2, 3, 4, 5]
The element is: 5


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.