Thursday 25 December 2014

Java : Collection Framework : LinkedHashSet (toArrayParam)


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

LinkedHashSetExample.java
import java.util.LinkedHashSet;

/*
 * Example of toArray(T[] a) method.
 */
public class LinkedHashSetExample
{
    public static void main( String[] args )
    {
        LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();

        linkedHashSet.add("Rohan");
        linkedHashSet.add("Phil");
        linkedHashSet.add("Ram");
        linkedHashSet.add("Dave");
        linkedHashSet.add("Peter");

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

        String[] strArray = new String[linkedHashSet.size()];

        /*
         * linkedHashSet elements will be copied to StrArray
         */

        linkedHashSet.toArray(strArray);

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

    }
}

Output
linkedHashSet : [Rohan, Phil, Ram, Dave, Peter]

Rohan
Phil
Ram
Dave
Peter

To Download LinkedHashSetDemoToArrayParam Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/LinkedHashSetDemoToArrayParam.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