Tutorialspoint

headSet() method of Java NavigableSet Class

import java.util.NavigableSet;
import java.util.TreeSet;
public class Demo {
   public static void main(String[] args) {
		NavigableSet<Integer> set = new TreeSet<>();
		set.add(10);
		set.add(25);
		set.add(40);
		set.add(55);
		set.add(70);
		set.add(85);
		set.add(100);
		System.out.println("Returned Value = " + set.headSet(55));
		System.out.println("Returned Value (high endpoint included) = " + set.headSet(55, true));
   }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.