+ is left-associative, so numeric operands keep adding numerically until a String appears, after which everything to the right concatenates as text; the same numbers print differently depending on where the string sits.
System.out.println(1 + 2 + "=" + 1 + 2);
System.out.println("=" + 1 + 2);
3=12
=12
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27