Sobes.tech
Junior — Middle

Can you tell me about the String class and its main features?

sobes.tech AI

Answer from AI

The String class in Java represents an immutable sequence of characters. Main features:

  • Immutability: once a String object is created, it cannot be changed. Any operation that modifies the string creates a new object.
  • Storage: strings are stored as an array of char characters.
  • Optimization: strings use a string pool to save memory — identical literals refer to the same object.
  • Methods: provides many methods for string manipulation, such as length(), substring(), indexOf(), equals(), toLowerCase(), etc.

Example:

String s1 = "hello";
String s2 = s1.toUpperCase(); // s2 = "HELLO", s1 remains "hello"
Can you tell me about the String class and its main… - sobes.tech