package com.Melirn.Test;
/**
* @author:Melirn
* @e-mail:2227287556@qq.com
* @date:2021.5.13
*/
import java.util.ArrayList;
import java.util.List;
public class NewTitleTest {
public static void main(String[] args) {
NewTitle car = new NewTitle(1, "汽车", "梦聆");
NewTitle computer = new NewTitle(2, "ROG", "梦聆");
List newsTitlelist = new ArrayList();
newsTitlelist.add(car);
newsTitlelist.add(computer);
System.out.println("新闻条数是" + newsTitlelist.size() + "条");
System.out.println("第一种遍历ArrayList");
for (int i = 0; i < newsTitlelist.size(); i++) {
NewTitle title = (NewTitle) newsTitlelist.get(i);
System.out.println(i + ":" + title.getTitleName());
}
System.out.println("第二种遍历ArrayList");
for (Object obj : newsTitlelist) {
NewTitle newTitle = (NewTitle) obj;
System.out.println(newTitle.getTitleName());
}
System.out.println("第三种遍历ArrayList");
newsTitlelist.forEach(obj -> {
NewTitle newTitle = (NewTitle) obj;
System.out.println(newTitle.getTitleName());
}
);
}
}
运行结果如下: