char literal uses single quotes: 'A'String literal uses double quotes: "Hello"| Method | Purpose |
|---|---|
length() | number of characters |
charAt(i) | character at index i |
substring(a,b) | portion from a to b-1 |
indexOf(str) | first position of str, or -1 |
concat(str) | join two strings |
equalsIgnoreCase() | compare ignoring case |
compareTo() | lexicographic comparison |
split(regex) | break into a String[] array |
Unlike String, a StringBuilder can be modified in place — much more efficient when building/editing text in a loop instead of creating a new String each time.
isDigit(c), isLetter(c)isUpperCase(c), isWhitespace(c)toUpperCase(c), toLowerCase(c)Breaking text into tokens (words/sub-words) is the very first step of almost every text-processing pipeline.
Natural Language Processing (NLP) teaches computers to understand and generate human language. The string-handling techniques in this chapter — tokenizing, pattern matching, cleaning text — are the same foundational steps that large language models (LLMs) use before any AI-generated text is produced.
| Pattern | Matches |
|---|---|
\d | a digit |
\w | a word character |
+ * | one-or-more / zero-or-more |
^ $ | start / end of string |
| Method | Purpose |
|---|---|
length() | character count |
charAt(i) | char at index i |
substring(a,b) | portion of the string |
indexOf(s) | first position of s, or -1 |
replace(a,b) | swaps all occurrences of a with b |
split(regex) | breaks into a String[] |
trim()/strip() | removes leading/trailing whitespace |
compareTo(s) | lexicographic order |
| Method | Purpose |
|---|---|
append(x) | adds to the end |
insert(i, x) | inserts at index i |
delete(a,b) | removes characters a to b-1 |
reverse() | reverses the sequence |
setCharAt(i, c) | replaces a single character |
toString() | converts back to a String |
| Method | Purpose |
|---|---|
isDigit(c) | true if c is 0-9 |
isLetter(c) | true if c is a letter |
isLetterOrDigit(c) | true if letter or digit |
isWhitespace(c) | true if space/tab/newline |
isUpperCase(c)/isLowerCase(c) | case check |
toUpperCase(c)/toLowerCase(c) | case conversion |