Java Program to Remove All Elements of TreeSet Collection

Java Program to Remove All Elements of TreeSet Collection

Java Program to Remove All Elements of TreeSet Collection

// Java program to remove all elements of 
// TreeSet collection

import java.io.*;
import java.util.*;

public class Main {
  public static void main(String args[]) {
    TreeSet < Integer > tree = new TreeSet < Integer > ();

    tree.add(10);
    tree.add(20);
    tree.add(30);
    tree.add(40);
    tree.add(50);
    tree.add(60);

    System.out.println("TreeSet elements: " + tree);
    tree.clear();
    System.out.println("TreeSet elements: " + tree);
  }
}
TreeSet elements: [10, 20, 30, 40, 50, 60]
TreeSet elements: []

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment