Java TreeSet isEmpty() method

The isEmpty() is a method of TreeSet class. This method is used to check whether the set is empty or not. If the set is empty, it returns true else it returns false.

Syntax:

Specified by:

isEmpty in interface Collection<E> : If the collection contains no elements, it returns true.

isEmpty in interface Set<E> : If the set contains no elements, it returns true.

Return:

It returns true if the set contains no elements else returns false.

Example 1

Output:

TreeSet Empty or not: false
TreeSet Empty or not: true

Example 2

Output:

TreeSet 1 Empty or not: false
TreeSet 2 Empty or not: false
TreeSet 2 Empty or not: true