Java 8 introduced primitive iterators, that allow you to avoid boxing/unboxing during iteration over int, long and double collections.
You can create you own PrimitiveIterator
of byte
with typesafely implementing generic PrimitiveIterator<Byte,ByteConsumer>
. ByteConsumer
is also to be implemented. Both are pretty straightforward.
Why is there no PrimitiveIterator.ofByte
in jdk? Probably because of machine word size, that is usually not smaller than int. Or byte iterators are better done by streams and such.