Java TreeSet get Max/Min value

Description

Java TreeSet get Max/Min value

import java.util.TreeSet;

public class Main {
  public static void main(String[] args) {
    TreeSet<String> tSet = new TreeSet<String>();

    tSet.add("1");
    tSet.add("2");
    tSet.add("3");
    tSet.add("4");
    tSet.add("5");

    System.out.println("Lowest value : " + tSet.first());
    System.out.println("Highest value: " + tSet.last());
  }//  w w w.  j av a2 s .  c  o m
}



PreviousNext

Related