🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Java Notes
Topic #30

Concatenation


String Concatenation

The + operator can be used between strings to combine them. This is called concatenation:

Example

String firstName = "John";
String lastName = "Doe";
System.out.println(firstName + " " + lastName);

Note: that we have added an empty text (" ") to create a space between firstName and lastName on print.


Concatenation in Sentences

You can use string concatenation to build sentences with both text and variables:

Example

String name = "John";
int age = 25;
System.out.println("My name is " + name + " and I am " + age + " years old.");

The concat() Method

You can also use the concat() method to concatenate strings:

Example

String firstName = "John ";
String lastName = "Doe";
System.out.println(firstName.concat(lastName));

You can also join more than two strings by chaining concat() calls:

Example

String a = "Java ";
String b = "is ";
String c = "fun!";
String result = a.concat(b).concat(c);
System.out.println(result);

Note: While you can use concat() to join multiple strings, most developers prefer the + operator because it is shorter and easier to read.

Want to go beyond the notes?

Join CodingNow 2.0's Java course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Concatenation – FAQs

Quick answers about learning Concatenation in Java.

This free note from CodingNow 2.0 explains Concatenation in Java — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Java topic on CodingNow 2.0, including Concatenation, is 100% free with no signup required.
With focused practice, most students grasp Concatenation in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now