5

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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Hank Gay
  • 70,339
  • 36
  • 160
  • 222

1 Answers1

15

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
  • 40,336
  • 12
  • 74
  • 87
  • 3
    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 Jun 23 '10 at 17:05
  • 4
    Oh hell yes, Lists.partition() is way better than the other partition methods. It just returns sublist views without copying anything. – Kevin Bourrillion Jun 24 '10 at 07:01