AbstractSequentialList toString() method in Java with Example
Last Updated :
24 Dec, 2018
The toString() method of Java AbstractSequentialList is used to return a string representation of the elements of the Collection.
The String representation comprises a list representation of the elements of the Collection in the order they are picked by the iterator closed in square brackets[].This method is used mainly to display collections other than String type(for instance: Object, Integer)in a String Representation.
Syntax:
public String toString()
Parameter The method does not take any parameters.
Return This method returns a String representation of the collection.
Below examples illustrate the toString() method:
Example 1:
import java.util.*;
public class collection {
public static void main(String args[])
{
AbstractSequentialList<String> abs
= new LinkedList<String>();
abs.add( "Welcome" );
abs.add( "To" );
abs.add( "Geeks" );
abs.add( "For" );
abs.add( "Geeks" );
System.out.println(abs.toString());
}
}
|
Output:
[Welcome, To, Geeks, For, Geeks]
Example 2:
import java.util.*;
public class collection {
public static void main(String args[])
{
AbstractSequentialList<Integer> abs
= new LinkedList<Integer>();
abs.add( 10 );
abs.add( 20 );
abs.add( 30 );
abs.add( 40 );
System.out.println(abs.toString());
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...