Why is the toString method returning jibberish?
char[] arrays = {'a','b','c'};
{ a, b, c }
arrays.toString()
"[C@6519ceb1"
Why is the toString method returning jibberish?
char[] arrays = {'a','b','c'};
{ a, b, c }
arrays.toString()
"[C@6519ceb1"
What you are seeing is the string representation of the array object as an Object
. (The default behavior of toString()
for all objects is to print a representation of the object reference. You cannot override that behavior for arrays.) To get a string representation of the contents of the array, you need to either pass the character array to a String
constructor:
char[] arrays = {'a','b','c'};
String s = new String(arrays); // "abc"
or (depending on what you are trying to accomplish) use
String s = java.util.Arrays.toString(arrays); // "[a,b,c]"
char[] arrays = {'a','b','c'};
System.out.println(Arrays.toString(arrays));
This is using java.util.Arrays Implementation can be found
By default it is using Object class's toString implementation
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}