Skip to main content
Java Output Prediction Easy +10 XP

String Comparison

What does this print?

JavaRead-only
String a = "hello";
String b = "hello";
System.out.println(a == b);

What is the output?

Show answer and explanation

Answer: true

String literals are interned in Java. Both point to the same object in the string pool, so == returns true.

Hint: String literals share memory.

What this challenge tests

Output Prediction in Java: strings, comparison.

Related challenges