How to initialize all the elements of an array to any specific value in java
If it's a primitive type, you can use Arrays.fill()
:
Arrays.fill(array, -1);
[Incidentally, memset
in C or C++ is only of any real use for arrays of char
.]
There's also
int[] array = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};