concat method java code example
Example 1: string concat in java
public class ConcatenationExample {
public static void main(String args[]) {
String str1 = "Welcome";
str1 = str1.concat(" to ");
str1 = str1.concat(" String handling ");
System.out.println(str1);
String str2 = "This";
str2 = str2.concat(" is").concat(" just a").concat(" String");
System.out.println(str2);
}
}
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();