package nilpointer.net;
public class Student {
private String id;
private String name;
private int age;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Student(String id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public Student() {
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
package nilpointer.net;
import java.util.ArrayList;
import java.util.List;
public class Demo {
public static void main(String[] args) {
List<Student> students = new ArrayList<Student>();
students.add(new Student("st01", "Name 1", 20));
students.add(new Student("st02", "Name 2", 21));
students.add(new Student("st03", "Name 3", 22));
System.out.println("Student List");
students.forEach(student -> {
System.out.println(student.toString());
System.out.println("--------------------------------------");
});
}
}
Student List
Student [id=st01, name=Name 1, age=20]
--------------------------------------
Student [id=st02, name=Name 2, age=21]
--------------------------------------
Student [id=st03, name=Name 3, age=22]
--------------------------------------