Java常用工具——java集合
2020-12-13 05:30
                         标签:rgs   etc   get   tor   imp   插入   ati   arraylist   margin    一、ArrayList 二、案例 -公告的添加和显示 -在指定位置处插入公告 -删除公告 -修改公告 -编号 id  - 标题 title -创建人 creator -创建时间 createTime -构造方法 -获取和设置属性值的方法 3、删除、修改公告   Java常用工具——java集合 标签:rgs   etc   get   tor   imp   插入   ati   arraylist   margin    原文地址:https://www.cnblogs.com/loveapple/p/11142406.htmlpackage com.imooc.set;
import java.util.ArrayList;
import java.util.List;
public class ArrayListDemo {
    public static void main(String[] args) {
        // 用ArrayList存储编程语言的名称,并输出。
        //名称包括”Java”、”C”、”C++“、”Go”和”Swift”
        List list=new ArrayList();
        list.add("Java");
        list.add("C");
        list.add("C++");
        list.add("Go");
        list.add("Swift");
        //输出列表中元素的个数
        System.out.println("列表中元素的个数:"+list.size());
        
        //遍历输出所有编程语言
        System.out.println("==========================");
        for(int i=0;i
package com.imooc.set;
import java.util.Date;
public class Notice {
    //Notice类,属性:id,title,creator,ctreaterDate
    private int id;
    private String title;
    private String creator;
    private Date creatTime;
    //构造方法
    public Notice(int id, String title, String creator, Date creatTime) {
        super();
        this.id = id;
        this.title = title;
        this.creator = creator;
        this.creatTime = creatTime;
    }
    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 getCreator() {
        return creator;
    }
    public void setCreator(String creator) {
        this.creator = creator;
    }
    public Date getCreatTime() {
        return creatTime;
    }
    public void setCreatTime(Date creatTime) {
        this.creatTime = creatTime;
    }
    
    
    
    
}
package com.imooc.set;
import java.util.ArrayList;
import java.util.Date;
public class NoticeTest {
    public static void main(String[] args) {
        // 创建Notice类的对象,生成三条公告
        Notice notice1=new Notice(1,"欢迎来到java世界!","管理员",new Date());
        Notice notice2=new Notice(2,"请按时提交作业","老师",new Date());
        Notice notice3=new Notice(3,"考勤通知","老师",new Date());
        //添加公告
        ArrayList noticeList=new ArrayList();
        noticeList.add(notice1);
        noticeList.add(notice2);
        noticeList.add(notice3);
        //显示公告
        System.out.println("公告内容为:");
        for(int i=0;i
package com.imooc.set;
import java.util.ArrayList;
import java.util.Date;
public class NoticeTest {
    
    public static void main(String[] args) {
        // 创建Notice类的对象,生成三条公告
        Notice notice1=new Notice(1,"欢迎来到java世界!","管理员",new Date());
        Notice notice2=new Notice(2,"请按时提交作业","老师",new Date());
        Notice notice3=new Notice(3,"考勤通知","老师",new Date());
        //添加公告
        ArrayList noticeList=new ArrayList();
        noticeList.add(notice1);
        noticeList.add(notice2);
        noticeList.add(notice3);
        //显示公告
        System.out.println("公告内容为:");
        for(int i=0;i