Monday, 5 January 2015

Java : Collection Framework : TreeSet (descendingIterator)


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

TreeSetExample.java
import java.util.Iterator;
import java.util.TreeSet;

/*
 * Example of descendingIterator() 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 an iterator over the elements in this set in descending
         * order.
         */

        Iterator<Integer> iterator = treeSet.descendingIterator();
        while( iterator.hasNext() )
        {
            Integer value = (Integer) iterator.next();
            System.out.println(value);

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

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