- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The 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]
- Related Articles
- The containsAll() method of Java AbstractCollection class
- The isEmpty() method of Java AbstractCollection class
- The iterator() method of Java AbstractCollection class
- The toArray() method of Java AbstractCollection class
- The remove() method of Java AbstractCollection class
- The size() method of Java AbstractCollection class
- The addAll() method of Java AbstractCollection class
- The clear() method of Java AbstractCollection class
- The contains() method of Java AbstractCollection class
- The toArray(T[] a) T method of Java AbstractCollection class
- Override the toString() method in a Java Class
- Java toString() method.
- What is AbstractCollection class in Java?
- Convert Long into String using toString() method of Long class in java
- The toString() method of CopyOnWriteArrayList in Java

Advertisements