The Artima Developer Community
Sponsored Link

Java Buzz Forum
Iteration.each(): A closure view of iteration

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Iteration.each(): A closure view of iteration Posted: Feb 1, 2005 12:25 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: Iteration.each(): A closure view of iteration
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement
Looping through items in Java can be annoying. The most annoying part is how the construct for looping through an array/collection/string are not consistent. E.g for (int i = 0; i for (Iterator iterator = collection.iterator(); iterator.hasNext();) { We shouldn't have to think about this, and languages like Groovy let us get around it. Since, I like this, I decided to back-port the idea into Java code, so now I have the following available to me in Java: Iteration.each(collection, new ObjectUser() { public void use(Object o) { // do something with the element from the collection } }); Iteration.each(objectArray, new ObjectUser() { public void use(Object o) { // do something with the element from the Object[] } }); Iteration.each(string, new ObjectUser() { public void use(Object o) { // do something with the Character from the String } }); And there is also reverseEach(..) for the various data structures. Small things. NOTE: Commons-Collections does this

Read: Iteration.each(): A closure view of iteration

Topic: Java get/set - not that harmful. Version control for refactoring - harmful Previous Topic   Next Topic Topic: GMail Unavailable---Cross Your Fingers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use