Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initailize byte array of 100 bytes in java with all 0's

Tags:

java

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

like image 439
user1393608 Avatar asked May 10 '13 05:05

user1393608


1 Answers

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 ); 
like image 82
wolfcastle Avatar answered Oct 06 '22 08:10

wolfcastle