Join Strings in Java

To join strings in Java, use the String.join() method. The delimiter set as the first parameter in the method is copied for each element.

Let’s say we want to join the strings “Demo” and “Text”. With that, we want to set a delimeter $. For that, use the join() method as shown below −


The following is an example.


 Live Demo

public class Demo {
   public static void main(String[] args) {
      String str = String.join("$","Demo","Text");
      System.out.println("Joined strings: "+str);


Joined strings: Demo$Text
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know