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:
String string1 = "Dirask ";
String string2 = "is awesome!";
System.out.println(string1.concat(string2)); //"Dirask is awesome!"
1. Documentation
| 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. |
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!