We always concatenate two string in java use the concat() method of String Class,the specific string parameter append to the given string when use the concat() method.
Syntax
1 |
public String concat(String s) |
Parameter
1 |
s - a string that append to the given string. |
Return
A new string object.
Example of concatenate 2 string in java
1 2 3 4 5 6 7 |
public class Test { public static void main(String args[]) { String s = "Java Tutorial :"; s = s.concat("www.asenview.com"); System.out.println(s); } } |
output
1 |
Java Tutorial :www.asenview.com |
What is the tdifference of concatenation by using concat() method and "+" connector
1、concat() method just can concatenation two string,but the "+" connector can use to concatenation more than 2 string.
2、the "+" connector can use to concatenation a string and objects that is not string type.