Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Searching an ArrayList of Student objects using a passed String?

807606Feb 11 2007 — edited Feb 13 2007
I 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!

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 13 2007
Added on Feb 11 2007
19 comments
3,295 views