views:

60

answers:

1

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.

+8  A: 

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.

Kevin Bourrillion
@Kevin Bourrillion Related question: If I wanted to invoke `partition`-like logic on an array, you'd recommend `Lists.partition(Arrays.asList(myArray), mySize)` rather than `Iterators.partition(Iterators.forArray(myArray), mySize)`?P.S. Thanks for the great library.
Hank Gay
Oh hell yes, Lists.partition() is way better than the other partition methods. It just returns sublist views without copying anything.
Kevin Bourrillion