0% found this document useful (0 votes)
14 views

6.6 Java String Concat A

Uploaded by

mrnirajbro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

6.6 Java String Concat A

Uploaded by

mrnirajbro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like