Monday, 29 June 2015

Java : Collection Framework : Collections (fill)


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

CollectionsExample.java
import java.util.ArrayList;
import java.util.Collections;

/*
 *  Example of  
 *  fill(List<? super T> list,T obj) method
 */

public class CollectionsExample
{

    public static void main(String[] args)
    {

        ArrayList<Integer> arrayList = new ArrayList<Integer>();

        arrayList.add(2000);
        arrayList.add(3000);
        arrayList.add(4000);
        arrayList.add(1000);

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

        /*
         * Replaces all of the elements of the specified list with the specified
         * element.
         */

        Collections.fill(arrayList,20);

        System.out.println("After fill with '20', arrayList : " + arrayList);

    }

}
Output
arrayList : [2000, 3000, 4000, 1000]

After fill with '20', arrayList : [20, 20, 20, 20]
To Download CollectionsDemoFillApp Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/CollectionsDemoFillApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge