Mihail Stoynov's blog!
Surrender your ego
Thursday, July 10, 2008
Iterating over iterator contents with a for loop
How an iterator works:
Iterator i = collection.iterator();
while( i.hasNext() ) {
Object o = i.next();
//do stuff
}
Well, I want to move the red line in the loop init, so it would not mingle with the loop body where only business logic would reside.
Unfortunately that cannot happen. A
for
loop first inits the data, then checks the condition. With an iterator one has to first check if there are elements, then to get them.
And why would someone give you an iterator instead of a collection, my mind cannot understand. (
org.hibernate.Interceptor#postFlush(java.util.Iterator)
)
Comments [0]
|
Trackback
OpenID
Please login with either your
OpenID
above, or your details below.
Name
E-mail
(will show your
gravatar
icon)
Home page
Remember Me
Comment (Some html is allowed:
a@href@title, blockquote@cite, strike
) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.
Enter the code shown (prevents robots):
Live Comment Preview
dasBlog theme by
Mads Kristensen
RSS feed
Search
Archives
December, 2008 (2)
November, 2008 (15)
October, 2008 (16)
September, 2008 (30)
August, 2008 (15)
July, 2008 (14)
June, 2008 (26)
May, 2008 (6)
April, 2008 (21)
March, 2008 (14)
February, 2008 (28)
November, 2007 (5)
October, 2007 (7)
September, 2007 (1)
August, 2007 (7)
July, 2007 (3)
June, 2007 (1)
Blog Stats
Total Posts: 205
This Year: 0
This Month: 0
This Week: 0
Comments: 96
Categories
Did you know
Java
rulez
Sucks
БГ
Blogroll
Michael Moore (no rss)
Links
BG-JUG
Copyright policy
No rights reserved.
(You are going to
copy stuff anyway :)
If you mention my
name, thank you.
2009, Mihail Stoynov