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.
views:
60answers:
1
+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
2010-06-23 16:26:54
@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
2010-06-23 17:05:13
Oh hell yes, Lists.partition() is way better than the other partition methods. It just returns sublist views without copying anything.
Kevin Bourrillion
2010-06-24 07:01:16