String Concatenation
In java, string concatenation forms a new string that is the combination of multiple strings. There are two ways to concat string in java:
- By + (string concatenation) operator
- By concat() method
1) String Concatenation by + (string concatenation) operator
Java string concatenation operator (+) is used to add strings. For Example:
Output:Sachin Tendulkar
The Java compiler transforms above code to this:
In java, String concatenation is implemented through the StringBuilder (or StringBuffer) class and its append method. String concatenation operator produces a new string by appending the second operand onto the end of the first operand. The string concatenation operator can concat not only string but primitive values also. For Example:
Output
80Sachin4040
2) String Concatenation by concat() method
The String concat() method concatenates the specified string to the end of current string. Syntax:
Let's see the example of String concat() method.
Sachin Tendulkar
0 comments:
Post a Comment
Let us know your responses and feedback