import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.TreeSet;
public class MainClass {
public static void main(String[] a) {
String[] elements = new String[] { "A", "B", "C", "D" };
TreeSet set = new TreeSet(Arrays.asList(elements));
try {
Object last = set.last();
boolean first = true;
while (true) {
if (!first) {
System.out.print(", ");
}
System.out.println(last);
last = set.headSet(last).last();
}
} catch (NoSuchElementException e) {
System.out.println();
}
}
}
|