 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
 