How to initialize byte array of 100 bytes in java with all 0's. I want to create 100 byte array and initialize it with all 0's
A new byte array will automatically be initialized with all zeroes. You don't have to do anything.
The more general approach to initializing with other values, is to use the Arrays
class.
import java.util.Arrays; byte[] bytes = new byte[100]; Arrays.fill( bytes, (byte) 1 );
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