CODE
class StringConcatenationTest
{
public static void main(String arg[])
{
String s1 = "Aam";
String s2 = "Admi";
String s3 = s1.concat(s2); // LINE A
System.out.println(s3);
String s4 = s3 + "Party"; // LINE B
System.out.println(s4);
String s5 = "Shaked".concat(" Indian Politics"); // LINE C
System.out.println(s5);
}
}
AamAdmi
AamAdmiParty
Shaked Indian Politics
At LINE A
, adding s1
and s2
string variables using concat
method.
At LINE B
, "party"
is added to "AamAdmi"
using +
operator.
At LINE C
, adding two string literals and displaying the result.
concat
method for different string objects and string literals.+
operator for more than two string objects.String version = "Java Version".concat(1.7);
System.out.println(version);
concat
is not applicable to any other data type other than String
.String first = "Merit ";
String second = "Campus";
concat
method.