Java Collection Tutorial - Java SortedSet.first()








Syntax

SortedSet.first() has the following syntax.

E first()

Example

In the following code shows how to use SortedSet.first() method.

//w  w  w  .ja  va 2s  . c o  m
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
  public static void main(String[] argv) throws Exception {
    SortedSet<String> set = new TreeSet<String>();
    set.add("b");
    set.add("c");
    set.add("a");

    System.out.println(set.first());
  }
}

The code above generates the following result.