Skip to main content

Unit 1 · Using Objects and Methods

String Concatenation

Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.

What string concatenation covers

The + operator concatenates when at least one operand is a String, and adds when both operands are numeric. Java evaluates left to right, so the position of the first String in the expression decides whether earlier numbers are added or appended. Any primitive concatenated with a String is converted to its text form, and objects are converted using their toString method.

Where students lose points

"1" + 2 + 3 produces "123" while 1 + 2 + "3" produces "33", and mixing these up is the single most common concatenation error. Students also forget that parentheses force the arithmetic to happen first, which is exactly what a question is testing when it shows two nearly identical print statements.

How it shows up on the AP exam

Unit 1 material that appears constantly in output-tracing MCQs, because it lets the exam test evaluation order and type rules in a single short line of code.

For practice use only.

String Concatenation MCQ Practice

AP CSA String concatenation practice: how + mixes String and numeric operands, left-to-right evaluation order, and the output-tracing questions built on it.

Question 1 of 15

Answered 0 of 15

Choose one answer.

Which option matches the complete output produced by this segment?

public class ConcatenationTrace
{
    public static String build()
    {
        String result = "";
        result = result + 1;
        result = result + 2;
        return result;
    }

    public static void main(String[] args)
    {
        System.out.print(build());
    }
}
Choose one answer.