Searching an ArrayList of Student objects using a passed String?
807606Feb 11 2007 — edited Feb 13 2007I am having trouble searching through an ArrayList of Student objects using only a passed String. I have directions to read in a String value containing a key-value identifying a Student, and then finding the object-reference that matches that key-value in the students ArrayList. My directions say that I need the ability to search this list of objects, given a string. There are several ways to do this, supposedly. I was told that using an ArrayList, you can create a temp-object (of the same class) with the right key-value, and then use the indexOf() method in combination with get(). How do you do this?
For example, I will input to the program:
add Bob cs101
My Student constructor looks like:
// Student(): specific constructor
public Student(String nameOfStudent, double gradePointAverage) {
name = nameOfStudent;
setGPA(gradePointAverage);
courses = new ArrayList();
}
So I am supposed to use "Bob" from my input and be able to search through my students ArrayList in order to find the object referenced by "Bob". Can you please help me with this? I know this may be vague, so if you need any more information, please let me know. Thank you very much!