提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
替换ArrayList的所有元素
import java.util.ArrayList; import java.util.Collections;/**from 时 代 J a v a - nowjava.com**/ public class Main { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("A"); arrayList.add("B"); arrayList.add("D"); System.out.println("Before replacement, ArrayList contains : " + arrayList); Collections.fill(arrayList,"REPLACED");