Returning an Array from a Method in Java

A method may also return an array. For example, the following method returns an array that is the reversal of another array -


public static int[] reverse(int[] list) {
   int[] result = new int[list.length];
   for (int i = 0, j = result.length - 1; i < list.length; i++, j--) {
      result[j] = list[i];
   return result;