OneBite.Dev - Coding blog in a bite size

combine two strings in java

Code snippet on how to combine two strings in java

String str1 = "This is string ";
String str2 = "combined";

String str3 = str1 + str2;
System.out.println(str3); // Outputs "This is string combined"

This code creates two strings, str1 and str2 with the values “This is string ” and “combined”. The third string str3 is created by combining the first two strings using the + operator. Lastly, the combined string str3 is printed out using the System.out.println() method. The code is an easy way to combine two strings. The ’+’ operator is used to join two strings, which creates a new third string with the combined content of the two strings. The println() function is used to print the result on the screen.

java