I'm writing a method that prints every Object that is passed to it. This works fine by calling the Object.toString() method for the object but doesn't work for arrays. I can find out whether it is an Array with the Object.getClass().isArray() method, but I don't know how to cast it.
int[] a;
Integer[] b;
Object aObject = a;
Object bObject = b;
// this wouldn't work
System.out.println(Arrays.toString(aObject));
System.out.println(Arrays.toString(bObject));
Arrays.toStringif all you have is anObjectholding the array, and that is definitely not answered by the duplicate you proposed.