isEmpty() method

isEmpty(): This isEmpty Java string method is used to check whether the TreeSet contains any element or not. Basically, it checks the size of elements. 
return true, if TreeSet doesn’t contains any element.
return false, if TreeSet contains any element.

boolean isEmpty();

return type:  Its return type is boolean. It can return either true or false.

import java.util.TreeMap;

public class ExampleOfTreeMap 
{
	public static void main(String[] args) 
	{
		TreeMap<Integer, String> listOfNames = new TreeMap<Integer, String>();
		listOfNames.put(1, "JAVA");
		listOfNames.put(2, "GOAL");
		listOfNames.put(3, "SITE");
		
		
		System.out.println("Is list empty = "+ listOfNames.isEmpty());
		
	}
}

Output: Is list empty = false

Leave a Comment