So I have a list of a class type. For example, I have a ClassRoom class and a Student class.
I created an ArrayList of Students: ArrayList<Student> studList = new ArrayList<>();
I have a method to add a student, so index 0 is occupied:
public void addStudent(int studID, String studName, int studPhoneNum){
Student stud = new Student(studName, studID, studPhoneNum);
studList.add(stud);
System.out.println(studList);
}
Now what I want is to search for a specific value inside the student's variables. So for example, a student is represented by a name, ID and phone number. How do I loop over that Student list to find a student with a specific phone number, then print him or his phone number?
This is the function:
public void sendMessage(int phone){
for (Student s : studList) {
studList.get(studPhoneNum);
\\ then print the Student the phone number belongs to..
}
}
I do have a studPhoneNum variable set in the Student class.
if(s.getPhonenumber == phone)