� Using this method we can find out the invoking collection is empty or not. It returns true if the invoking collection is empty. Otherwise, returns false.
Collection Interface isEmpty() Method:
Using this method we can find out the invoking collection is empty or not. It returns true if the invoking collection is empty. Otherwise, returns false.
Syntax :
boolean isEmpty( );
Example :
import java.util.ArrayList;
import java.util.Collection;
public class CollectionInterfaceisEmptyMethod {
public static void main(String[] args) {
Collection collection = new ArrayList();
collection.add("Deepak");
collection.add("Kumar");
boolean result = collection.isEmpty();
if(result==true){
System.out.println("ArrayList is empty.");
}
else{
System.out.println("ArrayList is not empty.");
}
}
}
Output :
| ArrayList is not empty. |

[ 0 ] Comments