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

  1. Use .length() method
  2. Spaces count as characters
  3. Method returns an integer

Related Strings exercises

Practice all Strings exercises · Run this idea in the Java compiler