title: Program to reverse an array in Java
body: <p>I'm trying to invert an array, with the below-shown code, with no sucess. The output of the program is <code>7,0,0</code> and not <code>7,1,2</code> as its supposed to be. </p>
  
  <p>Code:</p>
  
  <pre><code>import java.util.Arrays;
  
  public class ReverseArray
  {
      public static void main(String[] args)
      {
          int[] data = {1, 2, 7};
          int[] dataR = reverseArray(data);
          System.out.println("Original Array: " + Arrays.toString(data));
          System.out.println("Reverse Array: " +  Arrays.toString(dataR));
      }
      public static int[] reverseArray(int[] data)
      {
          int[] reversedData = new int[data.length];
          int i;
          for(i=0; i &lt; data.length; i++);
          {
              reversedData[i] = data[(data.length - i -1)];
          }
          return reversedData;
      }
  }
  </code></pre>
  
  <p>All help appreciated, thanks.</p>