how to add strings together in java code example
Example 1: String concatenation in java
public class StringConcatMethodDemo
{
public static void main(String[] args)
{
String str1 = "Flower ";
String str2 = "Brackets";
String str3 = str1.concat(str2);
System.out.println(str3);
}
}
Example 2: 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 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");