Collections.fill(List <? super T> list, T obj) has the following syntax.
public static <T> void fill(List <? super T> list, T obj)
In the following code shows how to use Collections.fill(List <? super T> list, T obj) method.
/*from w w w. j a v a 2 s. c o m*/ import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static void main(String args[]) { // create array list object List<String> arrlist = new ArrayList<String>(); // populate the list arrlist.add("A"); arrlist.add("B"); arrlist.add("from java2s.com"); System.out.println("List elements before fill: "+arrlist); // fill the list Collections.fill(arrlist,"java2s.com"); System.out.println("List elements after fill: "+arrlist); } }
The code above generates the following result.