Languages
[Edit]
EN

Java - string concat method example

0 points
Created by:
Dirask Community
6300

In this article, we would like to show you how to concatenate one string to the end of another string using concat() method in Java.

Quick solution:

String string1 = "Dirask ";
String string2 = "is awesome!";

System.out.println(string1.concat(string2));  //"Dirask is awesome!"

 

1. Documentation

Syntaxpublic String concat(String str)
Parametersstr - the String to be concatenated to the end of this String.
ResultReturns a String representing the text of the combined strings.
Description

The method concatenates a string to the end of another string.

2. Practical example

In this example, we will concatenate string2 to the end of string1.

public class Example {
    public static void main(String[] args) {
        String string1 = "Dirask ";
        String string2 = "is awesome!";

        System.out.println(string1.concat(string2));
    }
}

Output:

Dirask is awesome!

Related posts

Java - String documentation

Native Advertising
ūüöÄ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

‚̧ԳŹūüíĽ ūüôā

Join