No, that solution is absolutely correct and very minimal.

Note however, that this is a very unusual situation: Because String is handled specially in Java, even "foo" is actually a String. So the need for splitting a String into individual chars and join them back is not required in normal code.

Compare this to C/C++ where "foo" you have a bundle of chars terminated by a zero byte on one side and string on the other side and many conversions between them due do legacy methods.

Answer from A.H. on Stack Overflow
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java array โ€บ join array of primitives with separator in java
Join Array of Primitives with Separator in Java | Baeldung
January 8, 2024 - ... String joined = Arrays.stream(intArray) .mapToObj(String::valueOf) .collect(Collectors.joining(separator)); When joining our char array with this method, we must first wrap the char array into CharBuffer and then project it to char again.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ convert character array to string in java
Convert Character Array to String in Java | Baeldung
January 8, 2024 - Considering we have a Character array, we can use the Collectors.joining() operation to form a String instance:
Discussions

How to concat two char arrays in java? - Stack Overflow
It depends I guess. The simpler approach would be just to convert the char arrays to a String and concaternate the Strings. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Convert Character array to string in Java - Stack Overflow
I have a Character array (not char array) and I want to convert it into a string by combining all the Characters in the array. I have tried the following for a given Character[] a: String s = new 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
A quick and easy way to join array elements with a separator (the opposite of split) in Java - Stack Overflow
Iterating through an array requires either adding a condition (if this is not the last element, add the seperator) or using substring to remove the last separator. I'm sure there is a certified, efficient way to do it (Apache Commons?) ... As some users have already said, StringUtils.join() will do the job and it's been there forever. No need for Java 8. ... We should mention that this approach works only for List More on stackoverflow.com
๐ŸŒ stackoverflow.com
People also ask

What is a char array in Java?
In Java, a char array represents a sequence of characters stored in contiguous memory locations. It is denoted by the data type `char[]` and can be used to store and manipulate strings or individual characters.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ char array to string in java
Mastering Char Array to String Conversion in Java: A Comprehensive ...
What are the performance implications when converting a char array to a string?
The performance implications of converting a char array to a string depend on the method used. The constructor and valueOf() methods are generally efficient. However, using a StringBuilder or StringBuffer can be more effective when concatenating multiple characters or performing frequent modifications. It is important to consider your application's specific requirements and performance considerations.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ char array to string in java
Mastering Char Array to String Conversion in Java: A Comprehensive ...
How can I check if a string is empty or null after converting a char array to a string?
After converting a char array to a string, you can check if it is empty or null using standard string validation techniques. To check if the string is empty, you can use the `isEmpty()` method, which returns `true` if the string length is 0. To check for null, you can compare the string to `null` using the `==` operator.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ char array to string in java
Mastering Char Array to String Conversion in Java: A Comprehensive ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-guava-chars-join-method-with-examples
Java Guava | Chars.join() method with Examples - GeeksforGeeks
July 11, 2025 - array: which is an array of char values that are to be joined. Return Value: This method returns a string containing all the given char values separated by separator. Below programs illustrate the use of this method: Example 1: Java ยท
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ char array to string in java
Char Array to String in Java - Scaler Topics
May 31, 2022 - Collectors.joining(): This method of Collectors Class combines various elements of a character or string array into a single string object.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @anshikabhadouria1 โ€บ convert-char-array-to-string-in-java-63678b321950
CONVERT CHAR ARRAY TO STRING IN JAVA | by Anshika Singh | Medium
May 18, 2021 - String#copyValueOf is another method that's semantically equivalent to the valueOf() method but was of any significance only in a first few Java releases. As of today, the copyValueOf() method is redundant and we don't recommend using it. ... With Arrays.stream(T[] object) method, we can open a stream over an array of type T. Considering we have a Character array, we can use the Collectors.joining() operation to form a String instance:
๐ŸŒ
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); ?
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ char array to string in java
Mastering Char Array to String Conversion in Java: A Comprehensive Guide
October 1, 2026 - In this example, we have a character array `charArray` with the elements 'J', 'a', 'v', and 'a'. Using the `join('')` method on the `charArray`, we combine all elements into a string with an empty delimiter.
๐ŸŒ
Medium
medium.com โ€บ @idiotN โ€บ javas-string-join-method-explained-9126d8b360c7
Javaโ€™s String.join() Method Explained
September 8, 2024 - delimiter: The sequence of characters to be used as a delimiter between each string element. elements: The elements to join together. This can be a variable number of arguments (varargs) or an Iterable like a list or set. The method takes a delimiter and the elements to join. It inserts the delimiter between each element in the collection, array, or varargs, resulting in a single concatenated string.
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ java โ€“ how to join arrays
Java โ€“ How to join Arrays | mkyong.com
February 8, 2016 - The simplest way is add the Apache Commons Lang library, and use ArrayUtils. addAll to join arrays. This method supports both primitive and object type arrays. ... package com.mkyong.example.array; import org.apache.commons.lang3.ArrayUtils; ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ convert-character-array-to-string-in-java
How to Convert Character Array to String in Java? - GeeksforGeeks
July 15, 2025 - With the introduction of streams in java8, we straight away use Collectors in streams to modify our character input array elements and later uses joining() method and return a single string and print it.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-stringutilsjoin-in-java
What is StringUtils.join() in Java?
public static String join(final Object[] array, final char delimiter, final int startIndex, final int endIndex)
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ strings in java โ€บ java string join() method
Java String join() Method
January 8, 2025 - There are two forms of join methods in the Java String class or you can say it has two overloaded forms. One joins the number of strings provided as parameters and the other joins the array or list of strings by iterating them but the number of strings or the elements of the array or list must implement CharSequence Interface.
๐ŸŒ
TraceDynamics
tracedynamics.com โ€บ java-char-array-to-string
Java Char Array to a String: Guide and Best Practices
December 9, 2023 - No, both methods are essentially the same and can be used interchangeably for converting a char array to a String. You should check for null or empty arrays before conversion to avoid NullPointerException or to handle them as needed. Yes, Guava provides utilities like the Joiner class which can be used for this conversion, especially for joining with delimiters.
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ string-join-java
Using String.join Method in Java: Your Ultimate Guide
March 11, 2024 - The String.join() method in Java is a simple and effective way to concatenate, or join, strings. This method takes in a delimiter and an array of strings, and returns a single string that has all the strings joined with the specified delimiter.
๐ŸŒ
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 ...
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ java โ€บ how-to-join-elements-of-string-array-with-delimiter-in-java
How to Join Elements of String Array with Delimiter in Java?
December 24, 2020 - To join elements of given string array with a delimiter string, use String.join() method. Call String.join() method and pass the delimiter string followed by the string array. String.join() returns a single string with all the string elements ...