How to check TreeSet Empty Or not

import java.util.Set;
import java.util.TreeSet;

public class IsEmpty {

public static void main(String[] args) {

Set<String> ts = new TreeSet<String>();
ts.add(“mumbai”);
ts.add(“delhi”);
ts.add(“kolkata”);
ts.add(“chandigarh”);
ts.add(“dehradun”);

// print treeset
System.out.println(” ts =”+ts);

System.out.println(“Is Empty = “+ts.isEmpty());

Set<String> set = new TreeSet<String>();

System.out.println(“Is Empty = “+set.isEmpty());

}

}

Output:

ts =[chandigarh, dehradun, delhi, kolkata, mumbai]

Is Empty = false

Is Empty = true

Related Posts:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

86 + = 96