Open In App

AbstractSequentialList toString() method in Java with Example

Last Updated : 24 Dec, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

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:




// Java program to demonstrate
// Abstract Collection toString() method
  
import java.util.*;
  
public class collection {
    public static void main(String args[])
    {
        // Creating an Empty AbstractSequentialList
        AbstractSequentialList<String> abs
            = new LinkedList<String>();
  
        // Use add() method
        // to add elements to the Collection
        abs.add("Welcome");
        abs.add("To");
        abs.add("Geeks");
        abs.add("For");
        abs.add("Geeks");
  
        // Using toString() method
        System.out.println(abs.toString());
    }
}


Output:

[Welcome, To, Geeks, For, Geeks]

Example 2:




// Java program to demonstrate
// Abstract Collection toString() method
  
import java.util.*;
  
public class collection {
    public static void main(String args[])
    {
        // Creating an Empty AbstractSequentialList
        AbstractSequentialList<Integer> abs
            = new LinkedList<Integer>();
  
        // Use add() method
        // to add elements to the Collection
        abs.add(10);
        abs.add(20);
        abs.add(30);
        abs.add(40);
  
        // Using toString() method
        System.out.println(abs.toString());
    }
}


Output:

[10, 20, 30, 40]


Previous Article
Next Article

Similar Reads

AbstractSequentialList isEmpty() method in Java with Example
The isEmpty() method of AbstractSequentialList in Java is used to check whether this AbstractSequentialList is empty or not. It returns an boolean value stating the same. Syntax: public boolean isEmpty() Parameters: This function has no parameters. Returns: The method returns an boolean value which states that this instance of the AbstractSequentia
2 min read
AbstractSequentialList removeAll() method in Java with Example
The removeAll() method of java.util.AbstractSequentialList class is used to remove from this list all of its elements that are contained in the specified collection. Syntax: public boolean removeAll(Collection c) Parameters: This method takes collection c as a parameter containing elements to be removed from this list. Returns Value: This method re
3 min read
AbstractSequentialList indexOf() method in Java with Example
The indexOf() method of java.util.AbstractSequentialList class is used to return the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index. Syntax: public in
2 min read
AbstractSequentialList clear() method in Java with Example
The clear() method of AbstractSequentialList in Java is used to remove all the elements from a list. The list will be empty after this call returns. Syntax: public void clear() Parameters: This function has no parameters. Returns: The method does not return any value. It removes all the elements in the list and makes it empty. Below examples illust
2 min read
AbstractSequentialList equals() method in Java with Example
The equals() method of java.util.AbstractSequentialList class is used to check if this AbstractSequentialList object is equal to the object passed as the parameter. This method returns a boolean value stating the same. Syntax: public boolean equals(Object o) Parameters: This method takes the object o as a parameter to be compared for equality with
2 min read
AbstractSequentialList contains() method in Java with Example
The contains() method of Java AbstractSequentialList is used to check whether an element is present in a Collection or not. It takes the element as a parameter and returns True if the element is present in the collection. Syntax: public boolean contains(Object element) Parameters: The parameter element is of type Collection. This parameter refers t
2 min read
AbstractSequentialList subList() method in Java with Example
The subList() method of AbstractSequentialList in Java is used to get a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this
2 min read
AbstractSequentialList hashCode() method in Java with Example
The hashCode() method of AbstractSequentialList in Java is used to get the hashCode value for this instance of the AbstractSequentialList. It returns an integer value which is the hashCode value for this instance of the AbstractSequentialList. Syntax: public int hashCode() Parameters: This function has no parameters. Returns: The method returns an
2 min read
AbstractSequentialList lastIndexOf() method in Java with Example
The lastIndexOf() method of java.util.AbstractSequentialList class is used to return the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index. Syntax: publi
2 min read
AbstractSequentialList conatinsAll() method in Java with Example
The containsAll() method of Java AbstractSequentialList is used to check whether two Collections contain the same elements or not. It takes one collection as a parameter and returns True if all of the elements of this collection is present in the other collection. Syntax: public boolean containsAll(Collection C) Parameters: The parameter C is a Col
2 min read