title: How to initialize all the elements of an array to any specific value in java
body: <p>In <code>C/C++</code> we have <code>memset()</code> function which can fulfill my wish but in <code>Java</code> how can i initialize all the elements to a specific value? Whenever we write <code>int[] array=new int[10];</code> , this simply initialize an array of size 10 having all elements equal to zero. I just want to change this initialization integer for one of my array. i.e. I want to initialize an array which has all elements equal to <code>-1</code>. Otherwise I have to put a <code>for</code> loop just after initialization, which ranges from index <code>0</code> to index <code>size-1</code> and inside that loop, I am assigning element to <code>-1</code>. Below is the code for more understanding-</p>
  
  <pre><code>    int[] array = new int[10];
      for (int i = 0; i &lt; size; i++) {
          array[i] = -1;
      }
  </code></pre>
  
  <p>Am i going correct? Is there any other way for the same?</p>