1TreeSet last() method when elements are String types.
2import java.util.TreeSet;
3public class TreeSetLastMethodExample
4{
5 public static void main(String[] args)
6 {
7 TreeSet<String> ts = new TreeSet<String>();
8 ts.add("grapes");
9 ts.add("banana");
10 ts.add("watermelon");
11 ts.add("apple");
12 // print last highest element
13 System.out.println("Last highest element is: " + ts.last());
14 }
15}
1import java.util.TreeSet;
2public class TreeSetLastMethodExample
3{
4 public static void main(String[] args)
5 {
6 TreeSet<Integer> ts = new TreeSet<Integer>();
7 ts.add(58);
8 ts.add(42);
9 ts.add(29);
10 ts.add(10);
11 // print last highest element
12 System.out.println("Last highest element is: " + ts.last());
13 }
14}