Languages
[Edit]
EN

Java - String concat() method example

0 points
Created by:
Lennie-S
439

In this article, we would like to show you how to concatenate two strings 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

Alternative titles

  1. Java - concatenate strings
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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