Monday 5 January 2015

Java : Collection Framework : TreeSet (PollLast)


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

TreeSetExample.java
import java.util.TreeSet;

/*
 * Example of pollLast() 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");

        /*
         * Retrieves and removes the last (highest) element, or returns null if
         * this set is empty.
         */

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

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

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

value : 50
treeSet : [10, 20, 30, 40]
To Download TreeSetDemoPollLast Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoPollLast.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