list 往指定的下标插入元素
import java.util.*;
public class ListExample{
public static void main(String[] args){
ArrayList<String> al=new ArrayList<String>();
al.add("Amit");
al.add("Vijay");
al.add("Kumar");
al.add(1,"Sachin"); // list往指定的下标插入元素
System.out.println("Element at 2nd position: "+al.get(2));
for(String s:al){
System.out.println(s);
}
}
}
参考答案
```
Element at 2nd position: Vijay
Amit
Sachin
Vijay
Kumar
```
Element at 2nd position: Vijay
Amit
Sachin
Vijay
Kumar
```