I need to search a LinkedList and compare the objects in the list so I don't add duplicates. I can't figure out how to pull a node so I can compare it to the StudentInfo object I'm trying to add. This is my attempt to use an iterator:
private LinkedList<CourseInfo> classes = new LinkedList<>();
public void addCourse(String cid, String name, String prof, String days,
String time, String room)
{
CourseInfo course = new CourseInfo(cid, name, prof, days, time, room);
Iterator i = classes.iterator();
while(i.hasNext())
{
if(i.equals(course))
{
System.out.println("Caught");
break;
}
}
}
I specifically need to compare the cid variables
HashSet. Find an object:list.contains(...).equals()andhashcode()in yourCourseInfoclass?