Java String Pool & Immutability Quiz

This Java quiz tests one of the most asked interview topics, the string pool and string immutability. You will predict what == and equals() print for literals, new String(), intern() and compile-time constants, and spot the code that throws.

Medium 10 questions ~6 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 a = "hi";
        String b = "hi";
        System.out.println(a == b);
    }
}
Show the answer

B. true Identical string literals are stored once in the string pool, so a and b point to the same object and == is true. That is an implementation detail of literals, not a reason to compare strings with ==.

What this quiz covers

  • == (same object) vs equals() (same text)
  • String literals and the string pool
  • new String() and intern()
  • Compile-time constant concatenation and final
  • Why String methods return new strings

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.