
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
toString Method of Java AbstractCollection Class
The toString() method of the AbstractCollection class is used to return the string representation of the elements of this collection.
The syntax is as follows
public String toString()
To work with AbstractCollection class in Java, import the following package
import java.util.AbstractCollection;
The following is an example to implement AbstractCollection toString() method in Java
Example
import java.util.ArrayList; import java.util.AbstractCollection; public class Demo { public static void main(String[] args) { AbstractCollection<Object> absCollection = new ArrayList<Object>(); absCollection.add("HDD"); absCollection.add("Earphone"); absCollection.add("Headphone"); absCollection.add("Card Reader"); absCollection.add("SSD"); absCollection.add("Pen Drive"); System.out.println("Count of Elements in the AbstractCollection = " + absCollection.size()); System.out.println("AbstractCollection = " + absCollection.toString()); } }
Output
Count of Elements in the AbstractCollection = 6 AbstractCollection = [HDD, Earphone, Headphone, Card Reader, SSD, Pen Drive]
Advertisements