Java Program to Get the Ceiling Item of Specified Value From TreeSet Collection

You are currently viewing Java Program to Get the Ceiling Item of Specified Value From TreeSet Collection

Java program to get the ceiling item of specified value from TreeSet collection

// Java program to get the ceiling item of specified value 
// 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(10);
    tree.add(20);
    tree.add(25);
    tree.add(30);

    int value = tree.ceiling(22);

    System.out.println("Ceiling value for 22: " + value);
  }
}

Output

Ceiling value for 22: 25

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