list 往指定的下標插入元素


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 ```


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM