Java Strings & String Methods Quiz

This Java strings quiz tests the String methods you use every day and the traps around them. You will predict the output of substring, indexOf and split, compare strings the right way and see why strings never change in place.

Easy 10 questions ~5 minutes Pass at 80% Java 17

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What does this print?

public class Main {
    public static void main(String[] args) {
        String s = "Hello";
        s.toUpperCase();
        System.out.println(s);
    }
}
Show the answer

B. Hello Strings are immutable: toUpperCase() returns a new string and leaves s alone. The result is thrown away here; write s = s.toUpperCase(); to keep it.

What this quiz covers

  • Strings are immutable
  • == vs equals() and equalsIgnoreCase()
  • substring, indexOf, charAt and their index rules
  • split and empty trailing strings
  • Concatenating null and using StringBuilder

Questions people ask

Do I need an account?

No. Anyone can play. Sign in to keep your XP, streak, badges and history.

Can I retake it?

Yes. Your best score is kept, and the questions and answers are shuffled each time.