Is the toSting() method of a char overridden? For an array of any type, if we print out the array name, we get the actual object address, but for char array, we get a neat listing of the actual contects.
The output is of the type:
The last one is the actual contents.
Anyone know why it is so?
"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
because thats how sequence of characters is handled by java. System.out.println doesn't call the "toString()" method on char arrays.
If you explicitly do ch.toString(), then the address of array will be printed just like other arrays.
]for details take a look into implementation of following methods:
println(char) -- print(char) -- write(int)
Thanks Minhaj, Neha,
My mistake, toString() is not called by println(). The method is overloaded for all of those. Interestingly, for the arrays, it is overloaded only for char. I guess rest of the arrays just go into the overloaded version that accepts an Object as argument.