package org.kodejava.util;
import java.util.SortedSet;
import java.util.TreeSet;
public class LastSetElement {
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 last
// item from the set using the last() method. The last item
// will be "Two".
String lastElement = numbers.last();
System.out.println("lastElement = " + lastElement);
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024