为了账号安全,请及时绑定邮箱和手机立即绑定

arrayListCURD20190701

标签:
Java
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;
    }
}
![图片描述](//img1.sycdn.imooc.com//5d1904640001f89d04380234.jpg)
![图片描述](//img1.sycdn.imooc.com//5d19047a0001f89d04380234.jpg)
![图片描述](//img1.sycdn.imooc.com//5d1904940001324e08800514.png)
![图片描述](//img1.sycdn.imooc.com//5d19049c0001933a02660131.jpg)
点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
Web前端工程师
手记
粉丝
37
获赞与收藏
165

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消