Java String join() with examples Last Updated : 08 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The java.lang.string.join() method concatenates the given elements with the delimiter and returns the concatenated string.Note that if an element is null, then null is added.The join() method is included in java string since JDK 1.8. There are two types of join() methods in java string. :public static String join(CharSequence deli, CharSequence... ele) and public static String join(CharSequence deli, Iterable<? extends CharSequence> ele) Parameters:deli- delimiter to be attached with each element ele- string or char to be attached with delimiterReturns : string joined with delimiter. java // Java program to demonstrate // working of join() method class GfG { public static void main(String args[]) { // delimiter is "<" and elements are "Four", "Five", "Six", "Seven" String gfg1 = String.join(" < ", "Four", "Five", "Six", "Seven"); System.out.println(gfg1); } } OutputFour < Five < Six < Seven java // Java program to demonstrate // working of join() method class GfG { public static void main(String args[]) { // delimiter is " " and elements are "My", // "name", "is", "Niraj", "Pandey" String gfg2 = String.join(" ", "My", "name", "is", "Niraj", "Pandey"); System.out.println(gfg2); } } OutputMy name is Niraj Pandey java // Java program to demonstrate // working of join() method class GfG { public static void main(String args[]) { // delimiter is "->" and elements are "Wake up", // "Eat", "Play", "Sleep", "Wake up" String gfg3 = String.join("-> ", "Wake up", "Eat", "Play", "Sleep", "Wake up"); System.out.println(gfg3); } } OutputWake up-> Eat-> Play-> Sleep-> Wake up Comment More infoAdvertise with us Next Article Java String join() with examples N Niraj_Pandey Follow Improve Article Tags : Java Java-Strings Java-lang package Java-Functions Practice Tags : JavaJava-Strings Similar Reads Java String concat() Method with Examples The string concat() method concatenates (appends) a string to the end of another string. It returns the combined string. It is used for string concatenation in Java. It returns NullPointerException if any one of the strings is Null.In this article, we will learn how to concatenate two strings in Jav 4 min read Java Guava | Longs.join() method with Examples The join() method of Longs Class in the Guava library is used to combine or join all the given long values separated by a separator. These long values are passed a parameter to this method. This method also takes the separator as the parameter. This method returns a String which is the result of joi 2 min read Stack toString() method in Java with Example The toString() method of Java Stack is used to return a string representation of the elements of the Collection. The String representation comprises a set representation of the elements of the Collection in the order they are picked by the iterator closed in square brackets[].This method is used mai 2 min read Java Relational Operators with Examples Operators constitute the basic building block to any programming language. Java too provides many types of operators which can be used according to the need to perform various calculations and functions, be it logical, arithmetic, relational, etc. They are classified based on the functionality they 10 min read Set add() method in Java with Examples The add() method of Set in Java is used to add a specific element into a Set collection. The set add() function adds the element only if the specified element is not already present in the set else the function returns False if the element is already present in the Set. Declaration of add() methodbo 2 min read Like