
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
The isEmpty Method of Java AbstractCollection Class
The isEmpty() method of the AbstractCollection class checks whether the collection is empty or not i.e. whether it has zero elements. It returns if the Collectionn has no elements.
The syntax is as follows −
public boolean isEmpty()
To work with AbstractCollection class in Java, import the following package −
import java.util.AbstractCollection;
The following is an example to implement AbstractCollection isEmpty() 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("Laptop"); absCollection.add("Tablet"); absCollection.add("Mobile"); absCollection.add("E-Book Reader"); absCollection.add("SSD"); absCollection.add("HDD"); System.out.println("AbstractCollection = " + absCollection); System.out.println("Collection is empty? = " + absCollection.isEmpty()); } }
Output
AbstractCollection = [Laptop, Tablet, Mobile, E-Book Reader, SSD, HDD] Collection is empty? = false
Let us see another example −
Example
import java.util.ArrayList; import java.util.AbstractCollection; public class Demo { public static void main(String[] args) { AbstractCollection<Object> absCollection = new ArrayList<Object>(); System.out.println("AbstractCollection = " + absCollection); System.out.println("Collection is empty? = " + absCollection.isEmpty()); } }
Output
AbstractCollection = [] Collection is empty? = true
Advertisements