357
In this example we show you how to join 2 strings in Java
We will give you 2 examples, there are several ways you can join 2 strings in Java
Examples
This example uses the String.concat() method
public class JavaApplication1 { public static void main(String[] args) { String myString1 = "String"; String myString2 = "example"; String concatString = myString1.concat(myString2); System.out.println("The concatenated string is: " + concatString); } }
Which displayed this
The concatenated string is: Stringexample
In this example we use the addition operator
public class JavaApplication1 { public static void main(String[] args) { String myString1 = "String"; String myString2 = "example"; String concatString = myString1 + myString2; System.out.println("The concatenated string is: " + concatString); } }
Which displayed this
The concatenated string is: Stringexample