Monday 5 January 2015

Java : Collection Framework : TreeSet (Ceiling)


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=y3FfbrxNwNk&list=UUhwKlOVR041tngjerWxVccw

TreeSetExample.java
import java.util.TreeSet;

/*
 * Example of ceiling(E e) method.
 */
public class TreeSetExample
{
    public static void main( String[] args )
    {

        TreeSet<Integer> treeSet = new TreeSet<Integer>();

        treeSet.add(40);
        treeSet.add(20);
        treeSet.add(30);
        treeSet.add(10);
        treeSet.add(50);

        System.out.println("treeSet : " + treeSet + "\n");

        /*
         * Returns the least element in this set greater than or equal to the
         * given element, or null if there is no such element.
         */
        Integer value = treeSet.ceiling(14);
        System.out.println("\nceiling(14) : " + value);

        value = treeSet.ceiling(21);
        System.out.println("\nceiling(21) : " + value);

        value = treeSet.ceiling(40);
        System.out.println("\nceiling(40) : " + value);

        value = treeSet.ceiling(53);
        System.out.println("\nceiling(53) : " + value);

    }
}
Output
treeSet : [10, 20, 30, 40, 50]


ceiling(14) : 20

ceiling(21) : 30

ceiling(40) : 40

ceiling(53) : null
To Download TreeSetDemoCeiling Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoCeiling.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment