VOOZH about

URL: https://www.geeksforgeeks.org/java/abstractcollection-tostring-method-in-java-with-examples/

⇱ AbstractCollection toString() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

AbstractCollection toString() Method in Java

Last Updated : 11 Jul, 2025

In Java, the toString() method is defined in the Object class and is inherited by all the Java classes. It is used to return a string representation of an object. The AbstractCollection class is a part of the Java Collections Framework, which overrides this method to provide a string representation of the collection.

Example 1: This example demonstrates how the toString() method of AbstractCollection returns a string representation of the collection's elements.


Output
[Geeks, for, Geeks]

Syntax of toString() Method

public String toString()

  • Parameter: The method does not take any parameters.
  • Return Type: This method returns a string representation of the collection.

Example 2: This example demonstrates the working of toString() method.


Output
[10, 20, 30, 40]
Comment