String Basics

A String is a sequence of characters. In many languages like Java and Python, strings are immutable, meaning they cannot be changed once created.

String Immutability and Constant Pool

Key Concepts

  • Immutability: Changing a string creates a new object in memory.
  • String Constant Pool (Java): A special memory region to save space by sharing identical string literals.
  • StringBuilder/StringBuffer: Mutable alternatives for efficient string manipulation.

Common Operations

Operation Complexity
Concatenation (Immutable) O(n)
Substring O(n)
Char Access O(1)
String Matching O(n*m) (Naive) or O(n) (KMP)

Problems

(No problems added yet)