Java Collections.fill(List <? super T> list, T obj)
Syntax
Collections.fill(List <? super T> list, T obj) has the following syntax.
public static <T> void fill(List <? super T> list, T obj)
Example
In the following code shows how to use Collections.fill(List <? super T> list, T obj) method.
// w ww . jav 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.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »