We can concatenate two strings in Java by using concat() method of String class. It concatenates the specified string to the end of this string. If the length argument of the string is 0 then this string object is returned otherwise a new string object is created.
Syntax: The syntax of the concat() method in java is given below:
Syntax: The syntax of the concat() method in java is given below:
public String concat(String str)
Here str, specifies the string to be concatenated at the end of another string.String Concatenate in Java by using concat() Method
We can concatenate the two string by using concat() method. It returns the newly created string object. Let's see the example.
class charAtExample{
public static void main(String args[]){
String str = "Java";
String str1 = str.concat("studypoint"); //concat the string
System.out.println("The newly concatenated string is: " +str1);
}
}
Output:
How to Concatenate two Strings using concat() Method in Java?
Reviewed by Prashant Srivastava
on
January 03, 2020
Rating:
No comments: