Skip to content

String tools

Read · 1 of 4

Handy methods

s.substring(a, b) is the part from position a up to (not including) b. s.indexOf("x") finds where something first appears (−1 if it doesn't). s.toUpperCase(), s.equals(t) and s.contains(t) do what they say.

Strings can't be changed. To build one piece by piece, use a StringBuilder: sb.append(x), then sb.toString(). sb.reverse() flips it.

A char is secretly a number: c - 'a' is 0 for 'a', 1 for 'b', and so on. That turns letters into array positions.