title: why doesn't binarySearch method return the correct result?
body: <p>Recently I am working on arrays in Java and I needed to use the method <code>binarySearch(arr, v)</code> in Arrays class to search the index of value <code>v</code> in the array <code>arr</code> if found.</p>
  
  <p>Then I do some tests with some different arrays. When I try to search value <code>4</code> in the array <code>{4, 3, 2, 1}</code> I found <code>-5</code>.</p>
  
  <p>Would someone can explain that please ?</p>
  
  <p>You can check here <a href="http://tpcg.io/kibBmw" rel="nofollow noreferrer">http://tpcg.io/kibBmw</a></p>
  
  <p>The code is below:</p>
  
  <pre><code>int[] arr   = {4, 3, 2, 1};
  System.out.println(Arrays.binarySearch(arr, 4));
  </code></pre>
  
  <blockquote>
    <p>-5</p>
  </blockquote>