TreeSet higher Example

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


TreeSet class higher example.Object higher(Object) Returns the least element in this set strictly greater than the given element, or null if there is no such element.

Here is the code

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

public class Higher {

    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);
        //Display higher element
        System.out.println("Higher element :"+treeset.higher(2));
    }
}

Output
treeset = [2, 5, 7]
Higher element :5

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

HOME | COPYRIGHT | CONTACT US