concatenate two string code example
Example 1: how add strings together
String firstName = "BarackObama";
String lastName = " Care";
System.out.println(firstName + lastName);
String name = firstName + lastName;
System.out.println(name);
System.out.println("BarackObama" + " Care");
Example 2: how to add strings together
String firstName = "BarackObama";
String lastName = " Care";
System.out.println(firstName + lastName);
String name = firstName + lastName;
System.out.println(name);
System.out.println("BarackObama" + " Care");
Example 3: how do you combine 2 strings
-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();