Menu
Coddy logo textTech

Concatenation

Lesson 4 of 16 in Coddy's Strings and Arrays in Java course.

It's possible to combine strings using the + operator,

String str1 = "Hello";
String str2 = "World";
System.out.println(str1 + " " + str2);

The string "Hello World" will be printed in the above example.

Note the space (" ") added in between str1 and str2

Or, use the concat() method,

String str1 = "Hello ";
String str2 = "World";
System.out.println(str1.concat(str2));
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

challenge icon

Challenge

Easy

Write a function named createFullName that gets two strings as arguments, the first name and the last name, and returns the concatenation of the two strings with a space in between.

Try it yourself

class CreateFullName {
    public static String createFullName(String firstName, String lastName) {
        // Write code here
    }
}

All lessons in Strings and Arrays in Java