Java Essential String Methods
Strings in Java come equipped with a rich suite of built-in manipulation methods. Mastering substring slicing, character inspection, containment checks, and array splitting allows you to parse and process textual data effortlessly.
"String methods are like a Swiss army knife for text: .charAt() is tweezers picking out a single letter, .substring() is scissors cutting out a coupon, and .split() is a paper slicer."
Deep Dive: How It Works
`.charAt(index)`: Returns the char at the specified 0-based position.
`.substring(start, end)`: Extracts characters from `start` (inclusive) up to `end` (exclusive).
`.contains("search")`: Returns true if substring exists.
`.split(",")`: Splits a string into a `String[]` array using a delimiter.
`.replace(old, new)`: Returns a new string with replaced characters.
Syntax Blueprint
String sub = text.substring(0, 4);
char first = text.charAt(0);
String[] parts = text.split(",");Remember that String methods return new strings without mutating original text.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Passing index == length() to charAt()Why it happens: String indices run from 0 to length() - 1. Calling text.charAt(text.length()) throws StringIndexOutOfBoundsException.
How to fix: Last character is at text.charAt(text.length() - 1).
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Extract first word from sentence
Given sentence = "Java is powerful", extract the first 4 characters using .substring(0, 4).
Print "First word: " + word.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.