String concat example in java

The concat method of string concatenates the specified string to the end of given string.

If the length of the argument string is 0, then given String object is returned. Otherwise, a new String object is created, representing a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string.

// String concat example in java
public class StringConcatExample {
    public static void main(String[] args) {
        // declare the String with some text
        String string = "some text here";
        // To concat other string in given string,
        // You need to use String's concat method as shown below
        String concated = string.concat(" concat this text");
        System.out.println("The Original String is : " + string);
        System.out.println("The String after concat : " + concated);

The output of above example will be as:

The Original String is : some text here
The String after concat : some text here concat this text