继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

arrayListCURD20190701

qaytix
关注TA
已关注
手记 104
粉丝 37
获赞 165
package altashna.java.arrayList.addData20190701;

import java.util.ArrayList;
import java.util.Date;


public class onload20190701 {
    public static void main(String[] args) {
        Notice notice1 = new Notice(1, "imooc java", "tahirjan", new Date());
        Notice notice2 = new Notice(2, "imooc python", "nurala", new Date());
        ArrayList list = new ArrayList();
        list.add(notice1);
        list.add(notice2);
        for (int i = 0; i < list.size(); i++) {
            Notice createObj = (Notice) list.get(i);
            System.out.println(createObj.getId());
            System.out.println(createObj.getTitle());
            System.out.println(createObj.getAdmin());
            System.out.println(createObj.getCreateTime());
        }
        Notice notice3 = new Notice(3, "imooc c++", "管理员", new Date());
        //末尾添加一条数据, add(int index,Object element) ()
        list.add(1, notice3); // 添加第一条公告的后面
        System.out.println("添加------");
        for (int i = 0; i < list.size(); i++) {
            Notice createObj = (Notice) list.get(i);
            System.out.println(createObj.getId());
            System.out.println(createObj.getTitle());
            System.out.println(createObj.getAdmin());
            System.out.println(createObj.getCreateTime());
        }
        System.out.println("删除------根据index方式删除");
        list.remove(2);
        for (int i = 0; i < list.size(); i++) {
            Notice createObj = (Notice) list.get(i);
            System.out.println(createObj.getId());
            System.out.println(createObj.getTitle());
            System.out.println(createObj.getAdmin());
            System.out.println(createObj.getCreateTime());
        }
        System.out.println("修改---------------------");
        //修改第二条公告的title内容
        notice2.setTitle("hello world");
        notice2.setId(0);
        //修改第三条公告的title内容
        notice3.setTitle("welcome windows");
        for (int i = 0; i < list.size(); i++) {
            Notice createObj = (Notice) list.get(i);
            System.out.println(createObj.getId());
            System.out.println(createObj.getTitle());
            System.out.println(createObj.getAdmin());
            System.out.println(createObj.getCreateTime());
        }
    }
}
class Notice {
    private int id;//id
    private String title;//标题
    private String admin;//创建人
    private Date createTime;//创建时间

    public Notice(int id, String title, String admin, Date createTime) {
        this.id = id;
        this.title = title;
        this.admin = admin;
        this.createTime = createTime;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAdmin() {
        return admin;
    }

    public void setAdmin(String admin) {
        this.admin = admin;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}
![图片描述](//img.mukewang.com/5d1904640001f89d04380234.jpg)
![图片描述](//img.mukewang.com/5d19047a0001f89d04380234.jpg)
![图片描述](//img.mukewang.com/5d1904940001324e08800514.png)
![图片描述](//img.mukewang.com/5d19049c0001933a02660131.jpg)
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP