TreeSet tailSet Example

TreeSet class tailSet example. This example shows you how to use tailSet method.


TreeSet class tailSet example.public SortedSet tailSet(Object fromElement) Returns a view of the portion of this set whose elements are greater than or equal to fromElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.

Here is the code

/**
 * @ # TailSet.java
 * A class repersenting use to TailSet method 
 * of TreeSet class in java.util package
 * version 23 May 2008
 * author Rose India 
 */
import java.util.*;

public class TailSet {

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

        // Create new element object and Add the elementreeset to the set:
        treeset.add(new Integer(2));
        treeset.add(new Integer(5));
        treeset.add(new Integer(7));

        System.out.println("treeset = " + treeset);

        SortedSet ss = treeset.tailSet(2);
        System.out.println("Tailset  : " + ss);
       
        ss = treeset.tailSet(3);
        System.out.println("Tailset  : " + ss);
    }
}

Output
 

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US