title: Cannot explain behaviour of copyOfRange(int[] a, int from, int to) function
body: <p>I was trying to do some slice copy using Arrays static function copyOfRegion. My code is given below:</p>
  
  <pre><code>public class MyJavaArrays {
      static int[] findEquilibPoint(int[] A) {
  
          int[] resArray = {-1};
          /* 
           * Our equilibrium condition is that the index must be between 0 and length
           * of the input array
           *
           */
           int l = A.length;
           int sum_l = 0;
           int sum_r = 0;
           int j = 0;
           for(int i=1; i&lt;l-1; i++) {
              sum_l=0;
              sum_r=0;
  
              int[] b1 = Arrays.copyOfRange(A,0,i-1);
              int[] b2 = Arrays.copyOfRange(A,i+1,l-1);
              System.out.println("START HERE..............\n");
              for (int s: b1)
                  System.out.print(s + ", ");
              System.out.println("\n............");
              for (int s: b2)
                  System.out.print(s + ", ");
              System.out.println("\n............");
              for (int x: b1){sum_l += x;}
              for (int y: b2){sum_r += y;}
              System.out.println(sum_l+" ?= "+sum_r);
              /* if the sums are equal, we have an equilibrium point */
              if (sum_l == sum_r) {
              resArray[j] = i;
              j++;
              }
           }
           return resArray;
      }
      public static void main(String[] args) {
          int[] A = {-1, 3, -4, 5, 1,-6, 2, 1};
          findEquilibPoint(A);        
  
      }
  </code></pre>
  
  <p>I tried to run it using different limits for <code>i</code> (l-1, l, l+1) and my investigation reveals that copyOfRange() method is actually doing <code>to-1</code>. My output for the code above is given below:</p>
  
  <pre><code>START HERE..............
  
  
  ............
  -4, 5, 1, -6, 2, 
  ............
  0 ?= -2
  START HERE..............
  
  -1, 
  ............
  5, 1, -6, 2, 
  ............
  -1 ?= 2
  START HERE..............
  
  -1, 3, 
  ............
  1, -6, 2, 
  ............
  2 ?= -3
  START HERE..............
  
  -1, 3, -4, 
  ............
  -6, 2, 
  ............
  -2 ?= -4
  START HERE..............
  
  -1, 3, -4, 5, 
  ............
  2, 
  ............
  3 ?= 2
  START HERE..............
  
  -1, 3, -4, 5, 1, 
  ............
  
  ............
  4 ?= 0
  </code></pre>
  
  <p>I can clearly see that after the first "START HERE............" statement, there is nothing! I am a bit puzzled, but is this any known bug? I also went to <a href="http://www.tutorialspoint.com/java/util/arrays_copyofrange_int.htm" rel="nofollow">Tutorialspoint website</a> to check if my understanding of copyOfRange was wrong. But it seems the chap is doing what I want to do.</p>
  
  <p>Any ideas/suggestion anybody?</p>