I need to iterate through all byte values (-128 to 127 inclusive). I could use an int
iterator, but then I have to cast each time to byte
. Using a byte
iterator has the problem that I can't test for b < 128
as it will overflow. I thought of using a while loop and doing the test before incrementing, which is my best solution so far. Is there a better approach?
Java bytes are signed so they have the values -128 to 127. Anyway, you shouldn't worry about casts and extra checks like that because they are trivial to optimize away. In fact, at the JVM level, there's no such thing as a byte variable. It's treated as an int anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With