The floor() method in TreeSet returns the greatest element in this set less than or equal to the given element, or null if there is no such element. In this code, the num TreeSet contains the elements {10, 20, 25, 30, 35}. The call num.floor(38) searches for the greatest element in the set less than or equal to 38. Since there is no element less than 38, the floor() method returns the greatest element in the set, which is 35.
import java.io.*; import java.util.*; public class GetFlooring { public static void main(String args[]) { TreeSet <Integer> num = new TreeSet <Integer>(); num.add(10); num.add(35); num.add(20); num.add(30); num.add(25); int value = num.floor(38); System.out.println("Flooring value for 38 : " + value); } }
Flooring value for 38 : 35
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions