by @codeexamples

How to concatenate strings in Java

Home » java » How to concatenate strings in Java

To concatenate strings we need to use plus + operator in Java.

In this below example, we are concatenating two strings by using + operator.

String first = "Code";
String last  =  "examples";

String combine = first + last;

System.out.println(combine);

Output:

Codeexamples

Using concat() method

Similarly, you can also use the concat() method to concatenate one string with another string.

String name = "Code";

System.out.println(name.concat("Java"));

Output:

Codejava