Get lowest and highest value stored in TreeSet - Java Collection Framework

Java examples for Collection Framework:TreeSet

Description

Get lowest and highest value stored in TreeSet

Demo Code


import java.util.TreeSet;
 
public class Main {
 
  public static void main(String[] args) {
    TreeSet tSet = new TreeSet();
    tSet.add("1");
    tSet.add("3");
    tSet.add("2");
    tSet.add("5");
    tSet.add("4");
   /*w  ww .  j  a v  a 2s  . co  m*/
    System.out.println("Lowest value Stored in Java TreeSet is : " + tSet.first());
   
    System.out.println("Highest value Stored in Java TreeSet is : " + tSet.last());
 
  }
}

Result


Related Tutorials