treeset isempty 28 29 method in java

Solutions on MaxInterview for treeset isempty 28 29 method in java by the best coders in the world

showing results for - "treeset isempty 28 29 method in java"
Aitana
20 Nov 2020
1import java.util.TreeSet;
2public class TreeSetIsEmptyMethodExample
3{
4   public static void main(String[] args)
5   {
6      TreeSet<String> ts = new TreeSet<String>();
7      ts.add("violet");
8      ts.add("green");
9      ts.add("red");
10      ts.add("yellow");
11      ts.add("blue");
12      ts.add("indigo");
13      System.out.println("Given TreeSet: " + ts);
14      // check for empty TreeSet
15      System.out.println("Is TreeSet empty? " + ts.isEmpty());
16      // clear TreeSet using clear() method
17      ts.clear();
18      // again check for empty TreeSet
19      System.out.println("Is TreeSet empty? " + ts.isEmpty());
20   }
21}