Friday, 7 November 2014

Java : Collection Framework : ArrayList (Constructor Accepts Collection)


Click here to watch in Youtube : https://www.youtube.com/watch?v=pnVMOYlXYFs

ArrayListExample.java
import java.util.ArrayList;
import java.util.HashSet;

/*
 *  Example of ArrayList(Collection<? extends E> c) Constructor.
 */
public class ArrayListExample
{

    public static void main( String[] args )
    {
        HashSet<String> hashSet = new HashSet<String>();
        hashSet.add("Ram");
        hashSet.add("Dave");
        hashSet.add("Rohit");

        System.out.println("hashSet : " + hashSet);

        /*
         * Constructs a list containing the elements of the specified
         * collection, in the order they are returned by the collection's
         * iterator.
         */
        ArrayList<String> arrayList = new ArrayList<String>(hashSet);

        System.out.println("arrayList : " + arrayList);

    }
}

Output
hashSet : [Rohit, Dave, Ram]
arrayList : [Rohit, Dave, Ram]

To Download ArrayListDemoParamCons Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/ArrayListDemoParamCons.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