插入一个元素

import java.util.ArrayList;

public class AddAnElement {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    ArrayList arrayList = new ArrayList();
        arrayList.add("1");
        arrayList.add("2");
        arrayList.add("3");
       
        arrayList.add(1,"INSERTED ELEMENT");
        System.out.println("ArrayList contains...");
        for(int index=0; index < arrayList.size(); index++)
          System.out.println(arrayList.get(index));
}

}
Console:
ArrayList contains...
1
INSERTED ELEMENT
2
3

你可能感兴趣的:(插入一个元素)