Java String concat
The Java String class concat() method combines specified string at the end of this string.
It returns a combined string. It is like appending another string.
Signature
The signature of the string concat() method is given below:
1. public String concat(String anotherString)
Parameter
anotherString : another string i.e., to be combined at the end of this string.
Returns
Java String concat() method example
FileName: ConcatExample.java
1. public class ConcatExample{
2. public static void main(String args[]){
String s1="java string";
3. // The string s1 does not get changed, even though it is invoking the method
4. // concat(), as it is immutable. Therefore, the explicit assignment is required here.
5. s1.concat("is immutable");
6. System.out.println(s1);
7. s1=s1.concat(" is immutable so assign it explicitly");
8. System.out.println(s1);
10. }}
Test it Now
Output:
java string
java string is immutable so assign it explicitly