String Length in Java: Explanation & Practice
Find the length of a string
Problem summary
Print the length of the string 'Hello World'.
Starter code
public class Main {
public static void main(String[] args) {
String text = "Hello World";
// Print the length
// Print: Length: <result>
}
}Expected output and test cases
- Length of Hello World
Length: 11
Hints
- Use .length() method
- Spaces count as characters
- Method returns an integer
Related Strings exercises
- Practice Convert to Uppercase in Java
- Practice Character at Index in Java
- Practice Extract Substring in Java
Practice all Strings exercises · Run this idea in the Java compiler