So, I've already discovered
Arrays.toString(arr);
So don't point me to this question.
My problem is just a tiny bit different. In this case, I don't have a native array pointer to the array in question. I have it as an Object pointer, and it could be an array of any type (primitive or otherwise). In this case, I can use the above toString() method by casting the Object pointer to Object[]. However, if the pointer is a primitive array, it will throw a runtime exception and crash. So?
Example:
double test[] = {1, 2, 3, 4};
Object t = test;
// Now how do I pretty print t as an array with no access to test?
I solved my problem with this:
public String unkObjectToString(Object o) {
if(!o.getClass().isArray()) return o.toString();
int len = Array.getLength(o);
String ret = "[";
for(int i = 0; i < len; i++) {
Object q = Array.get(o, i);
ret += unkObjectToString(q);
if(i == len - 1)
ret += "]";
else
ret += ", ";
}
return ret;
}