Closed GoogleCodeExporter closed 9 years ago
Arrays.asList do *not* use new (java.util.)ArrayList()
Original comment by jim.andreou
on 29 Oct 2008 at 9:24
fair enough
but it's still a 'backing collection' which retains references to objects
already
iterated over.
Original comment by jvdne...@gmail.com
on 29 Oct 2008 at 9:46
Thanks for pointing this out.
Since iterators are usually short-lived and require small amounts of memory,
I'm not
sure whether this issue is worth fixing.
Original comment by jared.l....@gmail.com
on 29 Oct 2008 at 6:28
I need it since I use *very* wide and deep trees of iterators/iterables, and
memory
usage peaks too high. This helps. Code pasted below.
@SuppressWarnings("unchecked")
public static <T> Iterator<T> concat2(final Iterator<? extends T> a, final
Iterator<? extends T> b) {
final Iterator[] items = new Iterator[] { a, b };
return new UnmodifiableIterator<T>() {
private Iterator<? extends T> current = items[0];
private int index = 0;
public boolean hasNext() {
while (!this.current.hasNext() && (this.index < items.length)) {
this.current = items[this.index];
items[this.index++] = null;
}
return this.current.hasNext();
}
public T next() {
if (hasNext()) {
return this.current.next();
}
return null;
}
};
}
Feel free to use should you decide to fix it anyway. (same holds for
concat(Iterator<? extends T>... inputs))
Original comment by jvdne...@gmail.com
on 3 Nov 2008 at 11:47
Original comment by kevin...@gmail.com
on 17 Sep 2009 at 5:58
This issue has been moved to the Guava project (keeping the same id number).
Simply replace 'google-collections' with 'guava-libraries' in your address
bar and it should take you there.
Original comment by kevinb@google.com
on 5 Jan 2010 at 11:09
Original issue reported on code.google.com by
jvdne...@gmail.com
on 29 Oct 2008 at 9:20