Sample Java program to concatenate two strings using plus (+) concatenation operator.
public class StringConcatination {
public static void main(String args[]) {
String str1 = "Hello";
String str2 = "JavaTechig";
// Concatenation
String str3 = str1.concat(str2);
System.out.println("str1 = " + str1);
System.out.println("str2 = " + str2);
System.out.println("str3 = " + str3);
String str4 = "Hello";
// checking equals
if (str4.equals(str1)) {
System.out.println("str4 is equal to str1");
} else {
System.out.println("str4 is not equal to str1");
}
}
}
Visited 3 times, 1 visit(s) today


