Monday 22 December 2014

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


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

LinkedHashSetExample.java
import java.util.LinkedHashSet;

/*
 * Example of for-each loop.
 */
public class LinkedHashSetExample
{
    public static void main(String[] args)
    {
        LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();

        linkedHashSet.add("Dave");
        linkedHashSet.add("Peter");
        linkedHashSet.add("Juli");
        linkedHashSet.add("Rohit");
        linkedHashSet.add("Virat");

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

        /*
         * Using for-each loop get each element from the LinkedHashSet.
         */

        for (String name : linkedHashSet)
        {
            System.out.println(name);
        }

    }
}

Output
linkedHashSet : [Dave, Peter, Juli, Rohit, Virat]

Dave
Peter
Juli
Rohit
Virat
To Download LinkedHashSetDemoForeach Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/LinkedHashSetDemoForeach.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