public class Concat {
String cat(String a, String b) {
a += b;
return a;
}
}
public class Main
{
public static void main(String[] args) {
String str1 = "Hello";
String str2 = "People";
String str3 = str1 + str2; // Concatinating two string variables
System.out.println(str3);
System.out.println(str3 + "!!!"); // Concatinating string variable with a string
}
}
String a = "Hello";
String b = " World";
String c = a+b;
class Main {
public static void main(String[] args) {
// create first string
String first = "Java ";
System.out.println("First String: " + first);
// create second
String second = "Programming";
System.out.println("Second String: " + second);
// join two strings
String joinedString = first.concat(second);
System.out.println("Joined String: " + joinedString);
}
}
-By using (+) operator
-By using concatenate method (concat()).
String strconcat3=strconcat2.concat(strconcat);
-By StringBuffer
-String strconcat= new StringBuilder().append("matt")
.append("damon").toString();
-By StringBuilder
- String strconcat2= new StringBuffer()
.append("matt").append("damon").toString();