Monday, 5 January 2015

Java : Collection Framework : TreeSet (lower)


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

TreeSetExample.java
import java.util.TreeSet;

/*
 * Example of lower(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 greatest element in this set strictly less than the given
         * element, or null if there is no such element.
         */

        Integer value = treeSet.lower(32);
        System.out.println("lower(32) : " + value);
        
        value = treeSet.lower(25);
        System.out.println("lower(25) : " + value);
        
        value = treeSet.lower(5);
        System.out.println("lower(5) : " + value);
    }
}
Output
treeSet : [10, 20, 30, 40, 50]

lower(32) : 30
lower(25) : 20
lower(5) : null
To Download TreeSetDemoLower Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoLower.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

    Google+ Followers

    Google+ Badge