Java Program to Get the Size of a TreeSet Collection

You are currently viewing Java Program to Get the Size of a TreeSet Collection

Java program to get the size of a TreeSet collection

// Java program to get size of a 
// 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(30);
    tree.add(20);
    tree.add(25);
    tree.add(10);

    System.out.println("TreeSet: " + tree);
    System.out.println("Size of TreeSet: " + tree.size());
  }
}

Output

TreeSet: [10, 20, 25, 30]
Size of TreeSet: 4

Ranjith

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

Leave a Reply