Java Concatenate String concat() Method Tutorial

In this section, we will learn what the String concat() method is and how to use it in Java.

What is Java String concat() Method?

The `concat()` method is used to concatenate two strings and return a new one, which is the combination of both strings.

Java concat() Method Syntax:

public String concat(String string2)

concat() Method Parameters:

The method takes one argument, and that is the string that we want to append to the end of the string that this method is used with.

concat() Method Return Value:

The return value of this method is a new string object that is the combination of both string objects attached to each other.

Example: using String concat() method

public class Simple {

    public static void main(String[] args) {
        String s = "Hello";
        String res = s.concat(" World");
        System.out.println(res);
    }
}

Output:

Hello World

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies