Java .concat()

Victoria-DR's avatar
Published Jul 26, 2021Updated Oct 5, 2021
Contribute to Docs

Returns a string that is the concatenation of the given strings.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours

Syntax

string.concat(String str)
  • str (required): A string value that will be concatenated, appended, to another string.

Example 1

Append the string dessert to flavor:

class FlavoredDessert {
public static void main(String[] args) {
String flavor = "Strawberry ";
String dessert = "Ice Cream";
System.out.println(flavor.concat(dessert));
// Output: Strawberry Ice Cream
}
}

Example 2

Concatenate the strings firstName, middleName, and lastName:

class FullName {
public static void main(String[] args) {
String firstName = "Kimberly ";
String middleName = "Angela ";
String lastName = "Rodriguez";
System.out.println(firstName.concat(middleName).concat(lastName));
// Output: Kimberly Angela Rodriguez
}
}

All contributors

Contribute to Docs

Learn Java on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours