If I print out a char array normally
char[] c = new char[]{'3','b','o'};
System.out.println(c); //prints 3bo
the output is a string. However, if I concatenate a String it prints the array memory location.
System.out.println("" + c); //prints [C@659e0bfd
I would have expected it to print as a String and I'm sure why this behavior happens. Any explanations?
Simplest form is:
Arrays.toString(c);
and if it is a 2D array, then use Arrays.deepToString
as follows:
Arrays.deepToString(twoDArray);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With