Junior — Middle
What encoding does the CharSequence interface in Java use?
sobes.tech AI
Answer from AI
The CharSequence interface in Java does not define a specific encoding because it represents a sequence of characters (char), and in Java, characters are stored in UTF-16 format.
That is, CharSequence works with characters as 16-bit values corresponding to UTF-16. This means that any implementations of CharSequence (such as String, StringBuilder) use UTF-16 to represent characters.
Example:
CharSequence cs = "Example";
for (int i = 0; i < cs.length(); i++) {
char c = cs.charAt(i);
System.out.println(c);
}
Here, each character is a UTF-16 code unit.