第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

List接口使用說明和總結(jié)

標簽:
Java

List接口是有序的集合,可以通过索引值随意访问元素。
1、List的插入元素操作

    public List<Course> courseToSelect;//创建存储数量类型为Course对象的序列
    public void addTest(){//插入元素操作
        courseToSelect = new ArrayList();

                 方法一:add()方法 ----------
        Course cr1 = new Course("1","数据结构");
        this.courseToSelect.add(cr1);//在序列的尾部插入
        Course cr2 = new Course("2","JAVA");
        this.courseToSelect.add(1, cr2);//在位置1处插入对象cr2,注意插入位置不能超过序列的size,否则会引发数组下标越界异常
                方法二:addAll()方法----------
        Course[] s = {new Course("4","数据库"),new Course("5","linux编程")};
        this.courseToSelect.addAll(Arrays.asList(s));//将数组的所有元素插入到序列的尾部,此处Arrays.asList(s)表示为将数组转换成List。
        this.courseToSelect.addAll(3,Arrays.asList(s));//将数组元素插入到3位置
    }

2、获取元素操作

public void printTest(){
        方法一:for循环遍历所有元素
        int size = this.courseToSelect.size();
        for(int i = 0;i<size;i++)
        {
            Course cr = (Course) this.courseToSelect.get(i);
            System.out.println("课程:"+cr.id+cr.name);
        }
        方法二:迭代器
        Iterator it = this.courseToSelect.iterator();
        while(it.hasNext()){
            Course cr = (Course) it.next();
            System.out.println("课程:"+cr.id+cr.name);
        }
        方法三:foreach
        for(Object obj:this.courseToSelect){
            Course cr = (Course)obj;
            System.out.println("课程:"+cr.id+cr.name);
        }
    }

3、改变元素

set()方法改变特定位置的对象    
this.courseToSelect.set(1, new Course("8","图的挖掘"));

4、删除元素

public void deletTest(){
        this.courseToSelect.remove(cr);//删除特定对象
        Course[] courses = {(Course) this.courseToSelect.get(4),(Course)this.courseToSelect.get(5)};
        this.courseToSelect.removeAll(Arrays.asList(courses));//删除多个对象
    }
點擊查看更多內(nèi)容
8人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消