I am new to Java and I am starting to work with ArrayLists
. What I am trying to do is create an ArrayList
for students. Each student has differen
What you need is something like the following:
import java.util.*;
class TestStudent
{
public static void main(String args[])
{
List StudentList= new ArrayList();
Student tempStudent = new Student();
tempStudent.setName("Rey");
tempStudent.setIdNum(619);
StudentList.add(tempStudent);
System.out.println(StudentList.get(0).getName()+", "+StudentList.get(0).getId());
}
}
class Student
{
private String fname;
private int stId;
public String getName()
{
return this.fname;
}
public int getId()
{
return this.stId;
}
public boolean setName(String name)
{
this.fname = name;
return true;
}
public boolean setIdNum(int id)
{
this.stId = id;
return true;
}
}