How to Concatenate Multiple Strings in Java? Last Updated : 02 Feb, 2024 Comments Improve Suggest changes Like Article Like Report 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 Strings StringBuilderStringJoinerHere, 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 // Java Program for Concatenation Using StringBuilder import java.util.*; // Driver Class public class ConcatenationExample { // Main Function public static void main(String[] args) { // Using StringBuilder StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(" Welcome "); stringBuilder.append(" To "); stringBuilder.append(" GeeksforGeeks "); String result = stringBuilder.toString(); System.out.println(result); } } Output Welcome To GeeksforGeeks Explanation of the above Program:This Java program demonstrates string concatenation using StringBuilder. It creates a StringBuilder named stringBuilder. At last, it combines words into a sentence using toString() and prints the result. 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 // Java Program for Concatenation Using StringJoiner import java.util.StringJoiner; // Driver Class public class ConcatenationExample { // Main function public static void main(String[] args) { // Using StringJoiner StringJoiner stringJoiner = new StringJoiner(" "); stringJoiner.add(" Welcome "); stringJoiner.add(" To "); stringJoiner.add(" GeeksforGeeks "); String result = stringJoiner.toString(); System.out.println(result); } } Output Welcome To GeeksforGeeks Explanation of the above Program:This Java program demonstrates string concatenation using the StringJoiner class. It creates a StringJoiner named stringJoiner with a space. It combines separate words into a single sentence using toString() and prints the result. Comment More infoAdvertise with us Next Article How to Concatenate Multiple Strings in Java? E eswararaobetha1 Follow Improve Article Tags : Java Java Programs Java-Strings Java Examples Practice Tags : JavaJava-Strings Similar Reads How to Optimize String Concatenation in Java? Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a special character â\0â. Since arrays are immutable(cannot grow), Strings are immutable as well. Whenever a change to a String is made, an entirely new String is cre 4 min read How to Pad a String in Java? Padding a String in Java involves adding extra characters, which may be spaces, zeros, or other given characters to the beginning or end of a string to meet a desired length. This is normally used in formatting outputs or aligning texts.Example:The String.format() method is a simple way to pad strin 3 min read Java Program to Concatenate Two List Concatenating two lists means merging two lists into a single list. Consider the given lists: LIST 1LIST 2LIST AFTER CONCATENATION There are several methods to perform concatenation operation: Using addAll() methodUsing streamUsing union() Method 1: Using addAll() method Syntax: addAll ( list name ) 3 min read Java Program to Replace Multiple Characters in a String In this program, we will be discussing various methods for replacing multiple characters in String. This can be done using the methods listed below: Using String.replace() methodUsing replaceAll() method Using replaceFirst() method Method 1: Using String.replace() method This method returns a new st 3 min read How to Find the Longest Common Prefix of Two Strings in Java? In this article, we will find the longest common prefix of two Strings in Java. Examples: Input: String 1= geeksforgeeks, String 2 = geezerOutput: âgeeâ Input: String 1= flower, String 2 = flightOutput: âflâ Methods to Find the Longest common Prefix of two Strings in JavaBelow are the methods by whi 4 min read String Class repeat() Method in Java with Examples The string can be repeated N number of times, and we can generate a new string that has repetitions. repeat() method is used to return String whose value is the concatenation of given String repeated count times. If the string is empty or the count is zero then the empty string is returned. Syntax: 1 min read Convert a String to Character Array in Java Converting a string to a character array is a common operation in Java. We convert string to char array in Java mostly for string manipulation, iteration, or other processing of characters. In this article, we will learn various ways to convert a string into a character array in Java with examples.E 2 min read How to Print List Items Without Brackets in Java? In Java, if you want to print the elements of a list without brackets [ ]. you need to manually iterate through the list and print each element separately. The brackets are automatically added when you directly print the entire list. In this article, we will discuss how to print list items without b 2 min read Convert a List of String to a comma separated String in Java Given a List of String, the task is to convert the List to a comma separated String in Java. Examples: Input: List<String> = ["Geeks", "ForGeeks", "GeeksForGeeks"] Output: "Geeks, For, Geeks" Input: List<String> = ["G", "e", "e", "k", "s"] Output: "G, e, e, k, s" Approach: This can be ac 1 min read Convert ArrayList to Comma Separated String in Java ArrayList is a part of collection framework and is present in java.util package. It provides us with dynamic arrays in Java. In order to convert ArrayList to a comma-separated String, these are the approaches available in Java as listed and proposed below as follows: Earlier before Java 8 there were 5 min read Like