提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
替换ArrayList指定索引处的元素
import java.util.ArrayList; public class Main {// from N o w J a v a . c o m public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); arrayList.set(1,"REPLACED ELEMENT"); System.out.println("ArrayList contains..."); for(int index=0; index < arrayList.size(); index++) System.out.println(arrayList.get(index)); //来 自 时代Java - N o w J a v a . c o m } }