Back to Lessons

Java String Class Methods

April 5, 2026

Java Strings

Immutable sequences of characters with rich method library.

String Operations

String str = "Hello World";
int len = str.length();           // 11
String sub = str.substring(0,5);  // "Hello"
boolean eq = str.equals("hello"); // false
String upper = str.toUpperCase(); // "HELLO WORLD"

Key Points

  • Strings are immutable (new objects created).
  • StringBuilder for mutable strings.
  • String pool for memory efficiency.
  • Common methods: charAt(), indexOf(), replace(), trim().