title: Why is a negative index value taken while inserting a new element into an java array?
body: <p>I was trying out a java code to insert a new element into an array, I understand most of the program except for a line of code: "int newindex = -index-1;". Why does a negative sign used in front of the index?</p>
  
  <p>Here is the full program:</p>
  
  <pre><code>public class ArrayManipulation2 {
  
      public static void main(String[] args) {
  
          int[] array = {6,3,5,2,-9,-5,-1,0};
          Arrays.sort(array);
          printArray(array);
  
          int index= Arrays.binarySearch(array, 1);
          int newindex = -index-1;
  
          array = insertElement(array, 1, newindex);
          printArray(array);
      }
  
  
      public static void printArray(int[] array){
  
          for(int i=0; i&lt;array.length; i++){
              if(i!=0){
                  System.out.print(", ");
              }
              System.out.print(array[i]);
          }
          System.out.println();
  
      }
  
      public static int[] insertElement(int[] orginal, int element, int index){
          int length = orginal.length;
          int[] destination = new int[length+1];
          System.arraycopy(orginal, 0, destination, 0, index);
          destination[index]=element;
          System.arraycopy(orginal, index, destination, index+1, length-index);
  
          return destination;
  
      }
  } 
  </code></pre>
  
  <p>I need to know why the new index is specified as "-index-1"?. </p>