Say, I have two references to an Object in a LinkedList List1:
LinkedList<Object> List1 = new LinkedList<Object>();
Object first;
Object last;
I don't want to use the list index of these objects to refer to them, because the length of my list changes. I think this would not work. Now I want to iterate through the sublist defined by first and last, where first defines the beginning of the sublist in List1 and last defines the end of the sublist in List1.
My problem now is that AFAIK I can't do something like
while (current != last){
// do something
current = someiterator.next();
}
because I'm comparing two objects that in general will point to different locations. Furthermore, I also can't compare the references by their value, because the list may have one value appearing several times. So how can I iterate through this sublist of List1?