Skip to main content
Java Output Prediction Medium +20 XP

StringBuilder

What is the output?

JavaRead-only
StringBuilder sb = new StringBuilder("Hello");
sb.append(" World").reverse();
System.out.println(sb);

What is the output?

Show answer and explanation

Answer: dlroW olleH

First appends ' World' making 'Hello World', then reverse() reverses the entire string.

Hint: Operations happen in order.

What this challenge tests

Output Prediction in Java: string-builder, methods.

Related challenges