![]() |
In Java programming, there are a lot of ways to concatenate multiple strings. For this, we have taken three or more String values then we concatenate those String values by using different ways. In this article, we have used two different ways, we will explain each method with one example for a better understanding of the concept. Methods to Concatenate Multiple StringsHere, we have used these two different ways to concatenate multiple Strings in Java rather than using the basic concat() method. Every way provides a unique solution for this problem. Now we will explain each method with examples in Java. Program to Concatenate Multiple Strings in JavaBelow are the implementations of the two methods: Method 1: StringBuilderThis is an approach for concatenating multiple Strings in Java, This StringBuilder class provides one method which is append() method. This method is used to append the string values and then take the result into one String value. Java
Output
Welcome To GeeksforGeeks Explanation of the above Program:
Method 2: StringJoinerThis is another approach for concatenate multiple Strings in Java. For this, we have used StringJoiner class in Java. After that we have created object for this StringJoiner class After that we have converted the result into String value. Java
Output
Welcome To GeeksforGeeks Explanation of the above Program:
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |