Fill value to a list in Java
Description
The following code shows how to fill value to a list.
Example
/*from www . j a v a 2 s.c o m*/
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class Main {
public static void main(String[] args) {
String[] coins = { "A", "B", "C", "D", "E" };
List src = new LinkedList();
for (int i = 0; i < coins.length; i++){
src.add(coins[i]);
}
System.out.println(src);
Collections.fill(src, "java2s.com");
Iterator liter = src.listIterator();
while (liter.hasNext())
System.out.println(liter.next());
}
}
The code above generates the following result.