+concat(str: string) return type string

import java.lang.String;
class concat{
                    public static void main(String[] arg){ 
                          String str1="Welcome";
                          String str2=" to Java";
                          String str3=str1.concat(str2);
                          System.out.println("str1.concat(str2): "+str3);
                         }
                     }

Output:  str1.concat(str2): Welcome to Java

String str3=str1.concat(str2);

Since string concatenation is heavily used in programming, java provides a convenient way to accomplish it. You can use the plus (+) sign to concatenate two or more strings. So the above statement is equivalent to

String str3=str1+str2;

The following code combines the strings str1, str2, "and" and "Smartprogrammeron.blogspot.in" into one string:
String str3=str1+str2+"and"+"Smartprogrammeron.blogspot.in";

Recall that the + sign can also concatenate a number with a string. In this case the number is converted into a string and then concatenated. Note that, at least one of the operands must be a string in order for concatenation to take place.

Popular posts from this blog

Shutdown Pc

Ellipse using OpenGl

String Comparisons