package org.kodejava.util;
import java.util.TreeSet;
import java.util.SortedSet;
public class FirstSetElement {
public static void main(String[] args) {
SortedSet<String> numbers = new TreeSet<>();
numbers.add("One");
numbers.add("Two");
numbers.add("Three");
numbers.add("Four");
numbers.add("Five");
// SortedSet orders the items it contains. We can get the first
// item from the SortedSet using the first() method. The fist item
// will be "Five".
String firstElement = numbers.first();
System.out.println("firstElement = " + firstElement);
}
}
Latest posts by Wayan (see all)
- How do I build simple search page using ZK and Spring Boot? - March 8, 2023
- How do I calculate days between two dates excluding weekends and holidays? - January 12, 2023
- How do I discover the quarter of a given date? - January 11, 2023