The first and last element in this TreeSet

ReturnMethodSummary
Efirst()Returns the first (lowest) element currently in this set.
Elast()Returns the last (highest) element currently in this set.

  import java.util.Arrays;
import java.util.TreeSet;

public class Main {
  public static void main(String args[]) throws Exception {
    String elements[] = { "java2s.com", "C", "D", "G", "F" };
    TreeSet<String> set = new TreeSet<String>(Arrays.asList(elements));
    System.out.println(set);
    System.out.println(set.first());
    System.out.println(set.last());
  }
}

The output:


[C, D, F, G, java2s.com]
C
java2s.com
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.