freetimestudys@gmail.com          +91-7097633380
  Login Here                        

String Concat:-

       Concat() method present in the String class and it is used to combine the two String.

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

        In the above statements “str1.concat(str2)” method concatenates “Hello ” and “freetimestudy.com” into a single string “Hellofreetimestudy.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="freetimestudy";
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);
}
}

intput and output

output:he is22years old,,freetimestudyhi,,six222,,six6