In Java, is a String an array of chars?

java, string

Solution

Strings are immutable objects representing a character sequence (`CharSequence` is one of the interfaces implemented by String). Main difference to char arrays and collections of chars: String cannot be modified, it's not possible (ignoring reflection) to add/remove/replace characters.

Internally they are represented by a char array with an offset and length (this allows to create lightweight substrings, using the same char arrays).

Example: ['F','o','o','H','e','l','l','o',' ','W','o','r','l','d'], offset=3, count=5 = `"Hello"`.

Problem

I want to know, if a `String` is a collection. I have read around but am still quite confused.

Original source