Java HashSet isEmpty() Method
Example
Check if a set is empty:
import java.util.HashSet;
public class Main {
public static void main(String[] args) {
HashSet<String> cars = new HashSet<String>();
System.out.println(cars.isEmpty());
cars.add("Volvo");
System.out.println(cars.isEmpty());
}
}
Definition and Usage
The isEmpty() method checks if the set has no items.
Tip: Use the size() method to get the number of items in a set.
Syntax
public boolean isEmpty()
Parameter Values
None.
Technical Details
| Returns: | true if the set has no items, and false if it has one or more items. |
|---|