Talk:Iterator

From CSSEMediaWiki
Revision as of 06:21, 20 October 2010 by Benjamin Gibson (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

I am just wondering why is there a ">" in the if-statement between name and lastName.

if(name > lastName){
     myIterator.remove();
 }

Maybe there is a special way of using the "greater as" to find out if two Strings are equal in Java that I am not aware of, but it would make more sense to me to do it like that:

if(name.equals(lastName)){
 myIterator.remove();
}

The example removes all names greater than lastName. The "lastName" is the last (alphabetically) name you want. If you have a lastName of John everyone with a name after John in the alphabet will be removed. Otherwise you could probably just go names.remove(name) without needing a loop at all. So lastName isn't someones last name. --David Thomson 02:16, 7 October 2008 (UTC)

Noted (in the Consequences section) that this pattern violates the Dependency inversion principle --Benjamin Gibson

Personal tools