EN
Java - String concat() method example
0 points
In this article, we would like to show you how to concatenate two strings using concat()
method in Java.
Quick solution:
xxxxxxxxxx
1
String string1 = "Dirask ";
2
String string2 = "is awesome!";
3
4
System.out.println(string1.concat(string2)); //"Dirask is awesome!"
Syntax | public String concat(String str) |
Parameters | str - the String to be concatenated to the end of this String. |
Result | Returns a String representing the text of the combined strings. |
Description |
The method concatenates a string to the end of another string. |
In this example, we will concatenate string2
to the end of string1
.
xxxxxxxxxx
1
public class Example {
2
3
public static void main(String[] args) {
4
5
String string1 = "Dirask ";
6
String string2 = "is awesome!";
7
8
System.out.println(string1.concat(string2));
9
}
10
}
Output:
xxxxxxxxxx
1
Dirask is awesome!