package zxd.work615;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Test2 {
public static void main(String[] args) {
//造新闻--存储新闻--使用新闻:条数:新闻标题,删除新闻
FirstNews new1 = new FirstNews("1","中考新闻","刘伦",new Date());
FirstNews new2 = new FirstNews("2","高考新闻","大鹏",new Date());
FirstNews new3 = new FirstNews("3","刘伦撞猪","毛东",new Date());
FirstNews new4 = new FirstNews("4","帅帅倾城一笑","周帅",new Date());
//存储新闻
List<FirstNews> list = new ArrayList<FirstNews>();//接口类型
list.add(new1);
list.add(new2);
list.add(new3);
list.add(new4);
//使用新闻:条数:新闻标题,删除新闻
System.out.println(list.size());
System.out.println(list.get(2).getCreater());
list.remove(2);//通过下标删除
list.remove(new1);//通过对象删除
list.add(1, new3);//通过下标添加
print(list);
System.out.println(list.contains(new1));//查找
System.out.println(list.indexOf(new3));
Object[] o = list.toArray();
System.out.println(((FirstNews)o[1]).getDate());
print2(list);
}
public static void print(List<FirstNews> list){
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getName());
}
}
//遍历新闻--用增强for循环
public static void print2(List<FirstNews> list){
for (FirstNews f : list) {
System.out.println(f.getId());
}
}
}