TreeSet floor Example

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


TreeSet class floor example.public Object floor(Object) Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.

Here is the code

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

public class Floor {

    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);
        //disylay floor element of the "4"
        System.out.println("floor element : "+treeset.floor(4));
    }
}

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

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

HOME | COPYRIGHT | CONTACT US