The size() and isEmpty() of java.util.Collection interface is used to check the size of collections and if the Collection is empty or not. isEmpty() method does not take any parameter and does not return any value.
Input:[99, 54, 112, 184, 2] Output:size = 5 and Collection is not empty Input: Output: size = 0 and Collection is empty
public int size()
Parameters: This method does not takes any parameters.
Return Value: This method returns the number of elements in this list.
Parameters: This method do not accept any parameter
Return Value: This method does not return any value.
Example 1: Using LinkedList Class
The elements in Collection : [99, 54, 112, 184, 2] Size of the collection 5 Is the LinkedList empty: false The new List is:  Is the LinkedList empty: true
Example 2: Using ArrayList Class
Size of the collection 3 Is the ArrayList empty: false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.