import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.NavigableSet;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
List list = Arrays.asList(3, 2, 4, 1, 5);
NavigableSet ns = new TreeSet(list);
System.out.println("Ascending order (default): " + ns);
Iterator descendingIterator = ns.descendingIterator();
StringBuilder sb = new StringBuilder("Descending order: ");
while (descendingIterator.hasNext()) {
int m = descendingIterator.next();
sb.append(m + " ");
}
System.out.println(sb);
int greatest = ns.lower(3);
System.out.println("Lower of 3 = " + greatest);
int smallest = ns.higher(3);
System.out.println("Higher of 3 = " + smallest);
}
}