6 ways to Concatenate Strings in Java (Bonus: Choose concatenation character)
We need to deal with Strings in real time projects, and concatenation of Strings is a common and important functionality. There are multiple ways supported in Java to concatenate 2 or more Strings. Let's try to understand what are our options: 1. Using the '+' operator This is the easiest and the most commonly used option. We can simply use '+' between 2 Strings to concatenate them. String s1 = "Hello" ; String s2 = "World" ; System . out . println ( s1 + s2 ) ; Output: HelloWorld 2. Using concat() function Java has inbuilt function for concatenation. + operator is used for addition operations as well. If you want your code to be specific and readable, concat() function is an easy approach. String s1 = "Hello" ; String s2 = "World" ; System . out . println ( s1 . concat ( s2 ) ) ; Output: HelloWorld 3. Using StringBuilder class StringBuilder class has inbuilt methond append(), which we can use for concatenati...