With the help of java, I have created concat() string method. In the example given below, I have used '+' operator , StringBuilder and StringBuffer Class to join string in java. The string concat() method combines specified string at the end of the primary string and returns combined string.
public class StringConcat{
public static void main(String args[]) {
String firstname = "Raj";
String lastname = "Tiwari";
// concatenate String
String name = firstname + " " + lastname;
System.out.println(name);
// using StringBuilder
StringBuilder sb = new StringBuilder(14);
sb.append(firstname).append(" ").append(lastname);
System.out.println(sb.toString());
// using StringBuffer
StringBuffer sBuffer = new StringBuffer(15);
sBuffer.append(firstname).append(" ").append(lastname);
System.out.println(sBuffer.toString());
}
}
0 Comment(s)