Monday, 29 December 2014

Java : Collection Framework : TreeSet (for-each loop)


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

TreeSetExample.java
import java.util.TreeSet;

/*
 * Example of for-each loop.
 */
public class TreeSetExample
{
    public static void main( String[] args )
    {

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

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

        System.out.println("treeSet : " + treeSet + "\n");
        /*
         * Using foreach loop get each element from the treeSet.
         */

        for( Integer value : treeSet )
        {
            System.out.println(value);
        }
    }
}
Output
treeSet : [10, 20, 30, 40, 50]

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