String Concatenation in Java
Learn beginner-friendly ways to join strings in Java using +, concat, StringBuilder, and String.format with clear examples.
Learn beginner-friendly ways to join strings in Java using +, concat, StringBuilder, and String.format with clear examples.
Author
Mr. Oz
Date
Read
6 mins
Level 1
String concatenation means joining pieces of text to make one string. In Java, start with the + operator for quick joins, use String.concat for two strings, prefer StringBuilder in loops for speed, and use String.format for readable templates.
Great for quick joins and short strings.
String greeting = "Hello, " + name + "!";
String fullName = first + " " + last;
Useful for chaining two or more existing strings.
String result = "Hello".concat(", ").concat(name);
Avoids creating many temporary strings when appending repeatedly.
StringBuilder sb = new StringBuilder();
sb.append(first).append(" ").append(last);
for (int i = 0; i < 3; i++) {
sb.append("!");
}
String message = sb.toString();
Readable formatting when mixing values and text.
String msg = String.format("%s scored %d points", name, score);
Great for building comma‑separated or other delimited strings.
String csv = String.join(", ", "red", "green", "blue");
Ready for more?
String.valueOf(x) or
Objects.toString(x, "")
String.join or streams with
Collectors.joining.
Level 1
Learn beginner-friendly ways to join strings in Java using +, concat, StringBuilder, and String.format with clear examples.
Author
Mr. Oz
Duration
6 mins
Level 2
A deeper look at how + and StringBuilder allocate objects under the hood.
Author
Mr. Oz
Duration
10 mins
Level 3
Bytecode, invokedynamic, StringConcatFactory recipes, and performance guidance.
Author
Mr. Oz
Duration
15 mins