Answers for "treeset last method java"

1

TreeSet last() method in java

import java.util.TreeSet;
public class TreeSetLastMethodExample
{
   public static void main(String[] args)
   {
      TreeSet<Integer> ts = new TreeSet<Integer>();
      ts.add(58);
      ts.add(42);
      ts.add(29);
      ts.add(10);
      // print last highest element
      System.out.println("Last highest element is: " + ts.last());
   }
}
Posted by: Guest on October-27-2020
1

TreeSet last() method in java

TreeSet last() method when elements are String types.
import java.util.TreeSet;
public class TreeSetLastMethodExample
{
   public static void main(String[] args)
   {
      TreeSet<String> ts = new TreeSet<String>();
      ts.add("grapes");
      ts.add("banana");
      ts.add("watermelon");
      ts.add("apple");
      // print last highest element
      System.out.println("Last highest element is: " + ts.last());
   }
}
Posted by: Guest on October-27-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language