Concatenation means to join two or more words or text strings together. There are two ways to concatenate string objects:
WAP to concatenate two strings
class concatenate{
public static void main(String args[])
{
String s=" Maninder"+" Singh"; //Using + operator
String s1="Hello";
System.out.println(s+"\n");
System.out.println(s1.concat(s)); //Using concat() function
}
}
Output of the program:
- By + (string concatenation) operator.
- By concat() method.
WAP to concatenate two strings
class concatenate{
public static void main(String args[])
{
String s=" Maninder"+" Singh"; //Using + operator
String s1="Hello";
System.out.println(s+"\n");
System.out.println(s1.concat(s)); //Using concat() function
}
}
Output of the program:
No comments:
Post a Comment