This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
It prints out It worked over and over again until I kill the operation.
So, obviously it's the way I'm reading it that's throwing me off. Can some explain this a little clearer to me.
Teaching yourself anything is always the cheapest way, but it definitely takes a lot of time and effort.<br /> <br />Thank you javaranch <a href="http://"http://faq.javaranch.com/view?HowToAskQuestionsOnJavaRanch"" target="_blank" rel="nofollow">Learn How to Ask Your Question</a> and be nice
Your reading is correct, except that hasNext() only queries the state of the Iterator -- it doesn't change it. You have to use the "next()" method to actually retrieve the next element and advance the iterator -- i.e.,
ok, so that makes more sense. If I don't go to the next element, it will stay there forever, but by calling next() it actually brings me to the next element. It was looping before, because it was never making it to the next element.
Thanks again. [ July 07, 2005: Message edited by: Nicholas Carrier ]
And of course with J2SE 5.0, you can use the enhanced for:
(Here myList is a List<String> as in the first post above.) Now we get the entire loop control in one line, with no need to write casts (they're handled implicitly for us). The only limitation is that if you needed to use other methods of the Iterator, like remove(), you can't do that with the henhanced for loop. The iterator is hidden from us - hasNext() and next() are called for us implicitly, but other methods are unavailable unless we revert to the traditional (pre-5.0) use of Iterator. Usually this is not a problem, but it's somethign to be aware of. [ July 12, 2005: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
Joined: Jan 31, 2004
Originally posted by Jim Yingst: And of course with J2SE 5.0, you can use the enhanced for:
Wow! how simple... I've to learn J2SE 5.0
Regarding J2SE 5.0, I've a question maybe you have an answer to... If I want to use J2SE 5.0 new features what is the least version of J2EE I have to use?. I mean, i guess it is not possible to use J2SE 5.0 features with J2EE 1.3, maybe the minimal would be J2EE 1.4?. Am I wrong?
[ July 12, 2005: Message edited by: Jorge Blaz ]
[ July 12, 2005: Message edited by: Jorge Blaz ] [ July 12, 2005: Message edited by: Jorge Blaz ]