Concatenating Strings in Java


Strings in Java can be concatenated using the + operator or the concat method.

Source Code

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

Use the + operator for readability when concatenating strings, especially with variables or literals.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments