java combine two strings code example
Example 1: java concatenate strings
public class Concat {
String cat(String a, String b) {
a += b;
return a;
}
}
Example 2: java best way to concatenate strings
String stringBuilderConcat = new StringBuilder()
.append(greeting)
.append(" ")
.append(person)
.append("! Welcome to the ")
.append(location)
.append("!")
.build();
Example 3: 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");