Java Program to Get the Smallest Item From the TreeSet Collection

Java program to get the smallest item from the TreeSet collection

// Java program to get the smallest item from 
// 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);

    int small = tree.first();

    System.out.println("Smallest item in TreeSet is: " + small);
  }
}

Output

Smallest item in TreeSet is: 10
Share on:

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

Leave a Comment