Monday 5 January 2015

Java : Collection Framework : TreeSet (higher)


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

TreeSetExample.java
import java.util.TreeSet;

/*
 * Example of higher(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 strictly greater than the given
         * element, or null if there is no such element.
         */

        Integer value = treeSet.higher(32);
        System.out.println("higher(32) : " + value);

        value = treeSet.higher(16);
        System.out.println("higher(16) : " + value);

        value = treeSet.higher(55);
        System.out.println("higher(55) : " + value);
    }
}
Output
treeSet : [10, 20, 30, 40, 50]

higher(32) : 40
higher(16) : 20
higher(55) : null
To Download DisplayAllHeadersApp Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoHigher.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