This post originated from an RSS feed registered with Java Buzz
by Matt Raible.
Original Post: Closures with CollectionUtils
Feed Title: Raible Designs ~ We Build Web Apps
Feed URL: http://static.raibledesigns.com/500.html
Feed Description: Opinions and tips on how to build web applications using Java. Currently using Hibernate, Struts, XHTML, CSS, Ant, JUnit and XDoclet.
Here's a pretty nifty trick for using closure's with Jakarta Commons CollectionUtils:
List list = new ArrayList();
...
CollectionUtils.forAllDo(list, new Closure() { public void execute(Object obj) {
// execute something for each item obj
}
});
I wonder if there's any performance hit from doing things this way vs. a good ol' Iterator? Hat tip to Anand Subramanian.