Program for String Concatenation in Java
In beneath program, I have executed these four methods to connect two strings. On the off chance that you discover anything absent or inaccurate, then please notice it by remarking beneath. Don’t hesitate to inquire as to whether you are getting any issue to comprehend the program.
The connection is the way toward joining at least two little strings from a greater string. String connection in java should be possible in four distinct manners given beneath.
- Utilizing + administrator
- Utilizing concat() method of String class
- Utilizing affix() method of StringBuffer class
- Utilizing affix() method of StringBuilder class
Program for String Concatenation in Java
class StringConcatenation
{
public static void main(String...s)
{
String s1="Hello",s2="World",s3,s4;
s3=s1+s2;
System.out.println(s3);
s4=s1.concat(s2);
System.out.println(s4);
StringBuffer s5=new StringBuffer().append(s1).append(s2);
System.out.println(s5);
StringBuilder s6=new StringBuilder().append(s1).append(s2);
System.out.println(s6);
}
}