05 / 19

What is the difference between a String and a Character Array?

Difficulty: 1/10

String vs Character Array

A character array is a mutable sequence of characters, while a String is a higher-level string abstraction whose behavior depends on the programming language. In Java, for example, String is immutable, whereas char[] is mutable.

  1. 1

    A String provides higher-level operations such as searching, slicing, comparison, and concatenation.

  2. 2

    A character array provides direct mutable access to individual characters.

  3. 3

    Java String objects are immutable.

  4. 4

    A char[] can be modified after creation.

  5. 5

    Character arrays can sometimes be preferable when sensitive character data must be explicitly cleared from memory, although memory clearing has platform-specific limitations.

Follow-up Questions

  • Why is Java String immutable?
  • When would you use char[] instead of String?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.