Google News
logo
Java String Methods
String Concat :
Concat() method present in the String class and it is used to combine the two String.

Example: String str1 = Hello ;
String str2 = freetimelearn.com;
System.out.println(str1.concat(str2));

In the above statements str1.concat(str2) method concatenates Hello  and freetimelearn.com into a single string Hellofreetimelearn.com. 

The same concatenation can be done by using + operator, which is called string concatenation operator.
String s3=str1+str2;
String concat programing
class Test 
{ 
public static void main(String[] args) 
{ 
String age="22"; 
String s="he is "+age+" years old."; 
System.out.println(s); 
String str1="freetmielearn"; 
String str2="hi"; 
String str3=str1.concat(str2); 
System.out.println(str3); 
int a=22;
String s1="he is "+a+" years old."; 
System.out.println(s1); 
String s2="six "+2+2+2; 
System.out.println(s2); 
String s3="six "+(2+2+2); 
System.out.println(s3); 
} 
}
Output :
he is22years old,freetmielearnhi,six222,six6