title: how i can check if an array contains only "1" in java?
body: <p>I have to check in a more elegant and generic way as possible if an Array only contains <code>"1"</code>.</p>
  
  <p>Consider that the index of the array correspons to a thread index, and that threads set the corresponding index to <code>"1"</code> when they finished their job.</p>
  
  <p>I've to check when all thread have finished their job, or in other word when the array only contains <code>"1"</code>. </p>
  
  <p>I've done that in the "main"</p>
  
  <pre><code>Object obj =  new Object();
  int[] flag = new int[] {0, 0, 0, 0, 0, 0};
  int [] ss = new int[]{1, 1, 1};
  for (int i = 0; i &lt; flag.length; i++) {         
      new Thread(new MioThread(i, flag, ss, 1, 0, bw, obj)).start();      
  }
  synchronized (obj) {
      obj.wait();
  }
  </code></pre>
  
  <p>while I've done that at the end of the "run" method:</p>
  
  <pre><code>synchronized (flag) {
      flag[threadIndex] = 1;
      boolean ok = true;
      for(int i = 0; i&lt; flag.length; i++){
          if(flag[i] == 0)
              ok = false;
      }
      if(ok) {
          synchronized(obj) {
              obj.notify();
          }
      }
  }
  </code></pre>