String Methods in Java

From the Java cheat sheet · Strings & Text Blocks · verified Jul 2026

String Methods

Common operations on immutable strings.

java
// Quick Reference
s.length()          s.charAt(0)
s.toUpperCase()     s.trim()  s.strip()
s.substring(1, 4)   s.split(",")
s.contains("x")     s.replace("a", "b")
💡 Strings are immutable - every "modifying" method returns a brand-new String.
⚡ Use .equals() (or .equalsIgnoreCase()) for content comparison, never ==.
📌 strip() is Unicode-aware; trim() only removes ASCII whitespace <= U+0020.
🟢 isBlank() checks for empty-or-whitespace; isEmpty() only checks length 0.
stringsmethods

More Java tasks

Back to the full Java cheat sheet