comparing objects in an ArrayList
Hi everyone!
I have an ArrayList of objects that have String parts. For example, the list contains Courses that have String names so it would be like course1.name
I need to check that a different Course being added to the list does not have the same name as one of the other courses already in the list. I tried using a for loop with Iterator but I can't get it to compare the names of the course because I can't do it.next().name
Is there a way to access the variables inside the object using a for loop?
My code is like this:
ArrayList<Course> a = new ArrayList<Course>();
a.add(aCourse);
for(Iterator it = a.iterator(); it.hasNext();)
{
if aCourse.name.compareTo(it.Next().name)) == 0)
... //rest of loop
}
Thanks.

