Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a generic equivalent to ArrayIterator from Apache Commons Collections?

ArrayIterator is handy (although I don't need the reset functionality), but like the rest of the Commons Collections stuff, it doesn't use generics. I checked Google Collections, but I didn't see a close equivalent. Did I miss it? Is there another library of similar reputation and quality as the first two that provides such a thing? Thanks.

like image 754
Hank Gay Avatar asked Jun 23 '10 15:06

Hank Gay


People also ask

What is Apache Commons collections used for?

Description: The Apache Commons Collections is a project used to develop and maintain a collection of classes based on and inspired by the Java Development Kit (JDK) collection framework. This group of collections includes features such as: Bag interfaces for collections that have a number of copies of each object.

What is Java CollectionUtils?

Simply put, the Apache CollectionUtils provides utility methods for common operations which cover a wide range of use cases and helps in avoiding writing boilerplate code. The library targets older JVM releases because currently, similar functionality is provided by the Java 8's Stream API.

How do you use CollectionUtils in Java?

MyObject res = CollectionUtils. find(myList, new Predicate<MyObject>() { @Override public boolean evaluate(MyObject o) { return o. getValue() >= 1 && o. getValue() <= 5; } });

What is collection utils?

CollectionUtils class of Apache Commons Collections library provides various utility methods for common operations covering wide range of use cases. It helps avoid writing boilerplate code. This library is very useful prior to jdk 8 as similar functionalities are now provided in Java 8's Stream API.


1 Answers

Arrays.asList(array).iterator()

Arrays.asList(array).subList(start, end).iterator()

These method calls are cheap -- they don't actually copy any data. The Arrays class is in java.util, of course.

like image 88
Kevin Bourrillion Avatar answered Oct 24 '22 07:10

Kevin Bourrillion