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:
import java.util.*;
import java.util.AbstractSequentialList;
public class AbstractSequentialListDemo {
public static void main(String args[])
{
AbstractSequentialList<String>
absqlist = new LinkedList<String>();
absqlist.add( "Geeks" );
absqlist.add( "for" );
absqlist.add( "Geeks" );
absqlist.add( "10" );
absqlist.add( "20" );
System.out.println( "AbstractSequentialList:"
+ absqlist);
System.out.println( "The element is: "
+ absqlist.get( 2 ));
}
}
|
Output:
AbstractSequentialList:[Geeks, for, Geeks, 10, 20]
The element is: Geeks
Example 2:
import java.util.*;
import java.util.AbstractSequentialList;
public class AbstractSequentialListDemo {
public static void main(String args[])
{
AbstractSequentialList<Integer>
absqlist = new LinkedList<Integer>();
absqlist.add( 1 );
absqlist.add( 2 );
absqlist.add( 3 );
absqlist.add( 4 );
absqlist.add( 5 );
System.out.println( "AbstractSequentialList:"
+ absqlist);
System.out.println( "The element is: "
+ absqlist.get( 4 ));
}
}
|
Output:
AbstractSequentialList:[1, 2, 3, 4, 5]
The element is: 5