Here is my code:
import java.util.Arrays;
import java.util.List;
public class ArrayDemo1 {
public static void main (String args[]) {
//reversing array and inspecting it using Arrays.deepToString()
int[] array1 = new int[] {1,2,3,4};
int[] reversed_array = ArrayDemo1.reverse(array1);
for (int i=0; i < reversed_array.length; ++i) {
System.out.println(reversed_array[i]);
}
System.out.println(Arrays.deepToString(reversed_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;
}
}
Error:
incompatible types: int[] cannot be converted to Object[]
It looks like in this post: What's the simplest way to print a Java array?
they use Arrays.deepToString to print out arrays of primitives right?
This is the code in that referenced post:
*// array of primitives:*
int[] intArray = new int[] {1, 2, 3, 4, 5};
*// for when you have other elements (other than strings) use the code below*
System.out.print(Arrays.deepToString(*your arrays name*));
*//output: [1, 2, 3, 4, 5]*