I made a method that search through an array list of objects. Then if the searchKey is found in the array list it will print this certain item.
Here is how I iterate through the array list if it contains the searchKey, but I just realized that it is impossible to compare a string and an object.
for(int x = 0; x < Student.students.size(); x ++){
if(Student.students.contains(searchKey))
System.out.print(Student.students.get(x));
}
Here's how I create the constructor and array list.
String firstName, lastName, course, yearLevel, gender;
Student(String firstName, String lastName, String course, String yearLevel, String gender)
{
this.firstName = firstName;
this.lastName = lastName;
this.course = course;
this.yearLevel = yearLevel;
this.gender = gender;
}
static ArrayList<Student> students = new ArrayList<Student>();