Replace All Elements Of ArrayList in Java
Description
The following code shows how to replace All Elements Of ArrayList.
Example
//from w w w . j a va2 s .c o m
import java.util.ArrayList;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("A");
arrayList.add("B");
arrayList.add("D");
System.out.println(arrayList);
Collections.fill(arrayList, "java2s.com");
System.out.println(arrayList);
}
}
The code above generates the following result.