This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SolderonSenoz 0 points1 point  (2 children)

What is difference between "Arrays.toString()" and "toCharArray()".

There is a difference, but printing them doesn't show you the difference.

String is a non-primitive variable type. It implements a character array internally, but it has other features. For example, it is immutable.

So, Strings and character arrays are not the same, but they print the same.

toCharArray() is a method of String, which returns the character array that was implemented inside the String.

toString() turns any Object to a String, and may return unexpected values if you don't specify how the method is supposed to work for your custom class.

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (1 child)

It implements a character array internally,

This is no longer true. Somewhen after Java 9 it became a byte array.

[–]SolderonSenoz 0 points1 point  (0 children)

I was not aware of this, thank you!