Because o
is known not be null, but e
isn't necessarily. Take this example from the code for LinkedList
:
for (Entry e = header.next; e != header; e = e.next) {
if (o.equals(e.element))
return index;
index++;
}
In this example, doing it this way round avoids the need to protect against e.element
being null for every item in the collection. Here's the full code that takes account of o
being null:
if (o == null) {
for (Entry e = header.next; e != header; e = e.next) {
if (e.element == null)
return index;
index++;
}
} else {
for (Entry e = header.next; e != header; e = e.next) {
if (o.equals(e.element))
return index;
index++;
}
}