This documentation is archived and is not being maintained.

SortedSet Interface

Visual Studio 2005

Represents a specialization of a Set object containing sorted elements.

Package: java.util

Assembly: vjslib (in vjslib.dll)


public interface java.util.SortedSet
    extends java.util.Set

The following example demonstrates the first, last, headSet, and tailSet methods of the SortedSet interface.

// sortedset_overview.jsl

import java.util.*;

public class Program
{
    public static void main(String[] args)
    {
        // Create a new TreeSet object:
        TreeSet ts = new TreeSet();

        // Add some elements:
        ts.add(new Integer(5));
        ts.add(new Integer(4));
        ts.add(new Integer(9));

        // Display the first and the last:
        System.out.println("The first element: " + ts.first());
        System.out.println("The last element: " + ts.last());

        // Display the headSet and the tailSet:
        System.out.println("The headSet: " + ts.headSet(ts.last()));
        System.out.println("The tailSet: " + ts.tailSet(ts.last()));
    }
}

/*
Output:
The first element: 4
The last element: 9
The headSet: [4, 5]
The tailSet: [9]
*/
Show: