Java treats Strings as constant objects. To hide this and for some performance improvements, there's an internal representation of the string value. (If you create e.g. two Strings with the same value, they might use the same memory location for the value.) If you want to dig deeper, you can find more details in the Java Language Specification, JLS $4.3.3 and the Java Virtual Machine Specification, e.g JVM $5.1
Unless the JLS or JVMS specifies it, these details are JVM / implementation specific. It looks like the current Oracle JVM uses an array of UTF-16 characters to represent the value of strings in memory. JEP 254: Compact Strings documents this (and a change in Java 9). If you look at it on a byte level (and we're talking about internals) an array of char is very similar to a string, so this distinction is somewhat academic and the char array just another way to look at a string.
There are multiple questions dealing with the concrete internal String representation (What is the Java's internal represention for String? Modified UTF-8? UTF-16?, Java String internal representation).
BUT: Unless you're working on JVM-level (JNI, hard core performance optimization, etc.) the internal representation shouldn't concern you! In your Java-Code, you still have a String object to program with. Your String s
is not a char array or even assignable to one; char[] ch = s;
gives you a type mismatch error (that's why you have a special method for that conversion ch = s.toCharArray();
).
It looks like the confusion comes from the variable inspector in Eclipse that shows String object also as a char array. A debugger in a Java IDE might not show you the "true" representation of an object, but merely a user-friendly view. (AFAIK you can even extend the Eclipse Inspector to show "more meaningful" versions of an object). For a String object Eclipse shows you the String literal and the equivalent character array, probably to make an analysis easier.
In other words: The internal representation of a String object might be an array of char, but this is not valid in your Java program. A String object stays a String object in your code!