Pre Java 8:

Apache's commons lang is your friend here - it provides a join method very similar to the one you refer to in Ruby:

StringUtils.join(java.lang.Iterable,char)


Java 8:

Java 8 provides joining out of the box via StringJoiner and String.join(). The snippets below show how you can use them:

StringJoiner

StringJoiner joiner = new StringJoiner(",");
joiner.add("01").add("02").add("03");
String joinedString = joiner.toString(); // "01,02,03"

String.join(CharSequence delimiter, CharSequence... elements))

String joinedString = String.join(" - ", "04", "05", "06"); // "04 - 05 - 06"

String.join(CharSequence delimiter, Iterable<? extends CharSequence> elements)

List<String> strings = new LinkedList<>();
strings.add("Java");strings.add("is");
strings.add("cool");
String message = String.join(" ", strings);
//message returned is: "Java is cool"
Answer from Martin Gladdish on Stack Overflow
🌐
Medium
medium.com › javarevisited › nuanced-string-joining-in-java-7db547c331d0
Nuanced String Joining in Java | Javarevisited
April 23, 2024 - The String.join static method takes a CharSequence delimiter and either an array of CharSequence for the elements, or some kind of Iterable<CharSequence>. We can use the ArrayAdapter class from Eclipse Collections to convert the Integer array to an Iterable<CharSequence>.
🌐
Medium
medium.com › javarevisited › make-or-append-me-a-string-c654f247373a
Make or append me a String in Eclipse Collections | Javarevisited
November 26, 2022 - If you noticed in the Eclipse Collections examples, I used ImmutableList<?> instead of ImmutableList<String>. This was intentional. Both makeString and appendString will work with any type, not just String. You do not have to convert a type to a String first. This is not the case for Java Streams, StringJoiner and String.join which I used in the original article.
Discussions

Java: convert List<String> to a join()d String - Stack Overflow
Note: I am a committer for Eclipse Collections. ... Craig P. Motlin · 26.8k1818 gold badges106106 silver badges128128 bronze badges ... I also notice the toString() underlying implementation issue, and about the element containing the separator but I thought I was being paranoid. Since I've got two comments on that regard, I'm changing my answer to: static String join... More on stackoverflow.com
🌐 stackoverflow.com
String.join method not working for array/stack despite me having updated JDK?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
8
1
January 18, 2022
JEP 430: String Templates (Preview) Proposed to Target Java 21
🌐 r/java
122
149
March 3, 2023
Externalize strings in java
Yes and yes. I have not used the Eclipse tools to do this, but putting string resources in properties files has been the proper way to externalize strings (especially UI strings) for decades. Suggestion: do a search for "resource bundles in Java" More on reddit.com
🌐 r/eclipse
2
4
April 1, 2021
🌐
Programiz
programiz.com › java-programming › library › string › join
Java String join()
class Main { public static void main(String[] args) { String str1 = "I"; String str2 = "love"; String str3 = "Java"; // join strings with space between them String joinedStr = String.join(" ", str1, str2, str3); System.out.println(joinedStr); } } // Output: I love Java
🌐
Javatpoint
javatpoint.com › java-string-join
Java String.join() Method
July 25, 2018 - Java Program to swap two string variables without using third or temp variable.
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java string › concatenating strings in java
Concatenating Strings in Java | Baeldung
May 8, 2025 - By using this class, instead of the String.join method, we can append Strings as the program runs; There’s no need to create the array first!
🌐
Reddit
reddit.com › r/javahelp › string.join method not working for array/stack despite me having updated jdk?
r/javahelp on Reddit: String.join method not working for array/stack despite me having updated JDK?
January 18, 2022 -

I'm trying to convert all the character elements in my stack into an element of type String. For example - if my stack has [a,b,c] then I want to use the .join method to create a string "abc".

This is how I'm calling the method:

Stack mystack = new Stack<>();
finalstring = String.join("/", mystack);

However, eclipse gives me the following error message: The method join(CharSequence, CharSequence...) in the type String is not applicable for the arguments (String, Object[])

IntelliJ gives me a similar error message. Searching this message up, the common agreement is that the reason this is happening is that I'm using an earlier version of Java. However, I am using Java 8. When I write in my command prompt java --version it says I'm using JDK 17. In Eclipse and IntelliJ, it also tells me the JDK I'm using is version 17.

I don't know why I'm still getting this error message. Any ideas would be greatly appreciated.

Top answer
1 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2 of 3
1
And if you try Stack mystack = new Stack<>(); String s = String.join("/", mystack); ?
🌐
W3Schools
w3schools.com › java › ref_string_join.asp
Java String join() Method
The join() method joins one or more strings with a specified separator.
🌐
Blogger
javarevisited.blogspot.com › 2019 › 05 › 2-ways-to-join-string-in-java-8-examples-stringjoiner.html
StringJoiner.join() and String.join() Example in Java 8
June 25, 2025 - Since it was a very common requirement you will find many programmers writing the same routines and making the same mistakes and often ending in StackOverflow to solve their problems. Thankfully Java 8 solved this problem once for all. The JDK 8 API provides a couple of more ways to join Strings like you can join String by using the StringJoiner class or you can join the String by calling the String.join() method.
🌐
CodeGym
codegym.cc › java blog › strings in java › java string join() method
Java String join() Method
January 8, 2025 - The java string join() method joins all the strings with a delimiter provided to this method. We don’t need to create any object for using this method because it is a static method of the Java String class...
🌐
BeginnersBook
beginnersbook.com › 2017 › 10 › java-string-join-method
Java String join() method
June 4, 2024 - The join() method of String class is introduced in Java 8. This method is used to concatenate strings with specified delimiter. It is also used to combine multiple elements of a collection with the specified separator.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-join-examples
Java String join() with examples - GeeksforGeeks
April 8, 2025 - join() method is included in java string since JDK 1.8. There are two types of join() methods in java string.
🌐
Java Experts
mindfirejavaexperts.wordpress.com › 2013 › 12 › 30 › eclipse-shortcut-to-replace-in-string-concatenation-with-stringbuilder
Eclipse Shortcut to Replace “+” in String Concatenation with StringBuilder | Java Experts
December 30, 2013 - Some of us might have come across String concatenation using "+" in the code which leads to memory leak issue there by affecting the performance of the application. Instead of "+" to concatenate a String we can use StringBuilder. Let’s think of a scenario where in the entire application or let say in 50% of…
🌐
Vultr Docs
docs.vultr.com › java › standard library › java › lang › string › join()
Java String join() - Concatenate Strings | Vultr Docs
December 27, 2024 - Define an array of strings. Use the join() method to concatenate the array’s elements.
🌐
iO Flood
ioflood.com › blog › string-join-java
Using String.join Method in Java: Your Ultimate Guide
March 11, 2024 - In this example, we have an array of strings words. We use the String.join() method with a space (‘ ‘) as the delimiter to join all the strings in the array. The result is a single string ‘Java is awesome’.
🌐
DEV Community
dev.to › satyam_gupta_0d1ff2152dcc › master-the-java-string-join-method-a-2025-guide-with-examples-best-practices-2oem
Master the Java String join() Method: A 2025 Guide with Examples & Best Practices - DEV Community
November 6, 2025 - Okay, cool, it joins strings. But where does this fit in a real project? Everywhere! Building CSV Data Need to generate a CSV line from a list of data? join() is your best friend. java List userData = List.of("John Doe", "john.doe@email.com", "New York"); String csvLine = String.join(",", userData); // Output: John Doe,john.doe@email.com,New York
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › join or append stream elements in java
Join or Append Stream Elements in Java
December 13, 2024 - Use filter() to remove nulls before joining. Stream<String> stringStream = Stream.of("Hello", null, "Java", "Streams"); String result = stringStream.filter(element -> element != null) .collect(Collectors.joining(", ")); System.out.println("Joined String: " + result); // Output: Hello, Java, Streams
🌐
How to do in Java
howtodoinjava.com › home › java array › join string array in java with comma or any separator
Join String Array in Java with Comma or Any Separator
3 weeks ago - The shortest way to join a String array in Java is String.join(“,”, array), which returns one String with the separator between every two elements and none after the last.