java循环list_Java中List集合的三种遍历方式(全网最详)
介绍3种方式遍历list集合
1 创建一个model
public class News{
private int id;
private String title;
private String author;
public News(int id, String title, String author) {
super();
this.id = id;
this.title = title;
this.author = author;
}
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 getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
方式一 第一种、最基础的遍历方式:for循环,指定下标长度,使用List集合的size()方法,进行for循
介绍3种方式遍历list集合 1 创建一个model public class News{ private int id; private String title; private String author; public News(int id, String title, String author) { super(); this.id = id; this.title = title; this.author = author; } 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 getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } } 方式一 第一种、最基础的遍历方式:for循环,指定下标长度,使用List集合的size()方法,进行for循