String methods in Java
The everyday string toolkit: trim, transform, search and slice.
var raw = " The quick brown fox ";
var text = raw.trim();
System.out.println(text.toUpperCase());
System.out.println(text.replace("quick", "sly"));
System.out.println(text.contains("fox"));
System.out.println(text.startsWith("The"));
System.out.println(text.substring(4, 9));
System.out.println(text.length());
How it works
trimstrips the whitespace both ends carried in.toUpperCase,replace,containsandstartsWithdo daily work.substring(4, 9)slices by start and end;lengthcounts chars.
Keywords and builtins used here
var
The run, in numbers
- Lines
- 9
- Characters to type
- 313
- Tokens
- 110
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 63 seconds.
Step 1 of 4 in Strings, step 4 of 29 in Language basics.