Module 3: Operators, Expressions, and Strings
Useful String Methods
Use a few high-value string methods to inspect and transform text without overwhelming the lesson with too many APIs.
Author
Java Learner Editorial Team
Reviewer
Technical review by Java Learner
Last reviewed
2026-04-16
Java version
Java 25 LTS
Learning goals
- Read string length
- Convert case with `toUpperCase()` or `toLowerCase()`
- Check whether text contains a smaller piece of text
Start small: You do not need dozens of string APIs on day one. A few useful methods go a long way.
Common methods: length() tells you how many characters are in the string. toUpperCase() and toLowerCase() change letter case. contains(...) checks whether one string appears inside another.
Method calls return new results: Many string methods return a value. That means you can print the result directly or store it in another variable.
Why this matters: String methods show how real Java APIs feel without throwing you into advanced topics too early.
Runnable examples
Length and case
public class Main {
public static void main(String[] args) {
String word = "Java";
System.out.println(word.length());
System.out.println(word.toUpperCase());
}
}Expected output
4 JAVA
Check if text contains something
public class Main {
public static void main(String[] args) {
String sentence = "Java learner";
System.out.println(sentence.contains("learn"));
}
}Expected output
true
Common mistakes
Writing `length` without parentheses
Use `length()` because it is a method call.
Mini exercise
Create a string and print its length and uppercase version.
Summary
- Methods are actions you can call on a string.
- `length()` and case conversion are very common.
Next step
Finish the module by learning how Java evaluates longer expressions.
Sources used