Iterate over all byte values – 128-127 without Java casting
•
Java
I need to traverse all byte values (- 128 to 127, including endpoints) I can use an int iterator, but I have to convert it to byte every time There is a problem with using byte iterators. I can't test B < 128 because it overflows I thought about using a while loop and testing it before incrementing, which is my best solution so far Is there a better way?
Solution
Java bytes are signed, so their values are - 128 to 127 In any case, you should not worry about similar casts and additional checks because they can be easily optimized In fact, at the JVM level, there is no such thing as byte variables In any case, it is treated as an int
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码