Here's what I came up with. There are several ways to do this and they depend on the tools you are using.


Using StringUtils and ArrayUtils from Commons Lang:

Use with AIint[] arr = new int[] {1, 2, 3, 4, 5, 6, 7};
String result = StringUtils.join(ArrayUtils.toObject(arr), " - ");

You can't just use StringUtils.join(arr, " - "); because StringUtils doesn't have that overloaded version of method. Though, it has method StringUtils.join(int[], char).

Works at any Java version, from 1.2.


Using Java 8 streams:

Something like this:

Use with AIint[] arr = new int[] {1, 2, 3, 4, 5, 6, 7};
String result = Arrays.stream(arr)
        .mapToObj(String::valueOf)
        .collect(Collectors.joining(" - "));

In fact, there are lot of variations to achieve it using streams.

Java 8's method String.join() works only with strings, so to use it you still have to convert int[] to String[].

Use with AIString[] sarr = Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new);
String result = String.join(" - ", sarr);

If you're stuck using Java 7 or earlier with no libraries, you could write your own utility method:

Use with AIpublic static String myJoin(int[] arr, String separator) {
    if (null == arr || 0 == arr.length) return "";

    StringBuilder sb = new StringBuilder(256);
    sb.append(arr[0]);

    //if (arr.length == 1) return sb.toString();

    for (int i = 1; i < arr.length; i++) sb.append(separator).append(arr[i]);

    return sb.toString();
}

Then you can do:

Use with AIint[] arr = new int[] {1, 2, 3, 4, 5, 6, 7};
String result = myJoin(arr, " - ");
Answer from spirit 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>.
🌐
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 - When joining our char array with this method, we must first wrap the char array into CharBuffer and then project it to char again. This is because the chars() method returns a Stream of int values.
Top answer
1 of 9
93

Here's what I came up with. There are several ways to do this and they depend on the tools you are using.


Using StringUtils and ArrayUtils from Commons Lang:

Use with AIint[] arr = new int[] {1, 2, 3, 4, 5, 6, 7};
String result = StringUtils.join(ArrayUtils.toObject(arr), " - ");

You can't just use StringUtils.join(arr, " - "); because StringUtils doesn't have that overloaded version of method. Though, it has method StringUtils.join(int[], char).

Works at any Java version, from 1.2.


Using Java 8 streams:

Something like this:

Use with AIint[] arr = new int[] {1, 2, 3, 4, 5, 6, 7};
String result = Arrays.stream(arr)
        .mapToObj(String::valueOf)
        .collect(Collectors.joining(" - "));

In fact, there are lot of variations to achieve it using streams.

Java 8's method String.join() works only with strings, so to use it you still have to convert int[] to String[].

Use with AIString[] sarr = Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new);
String result = String.join(" - ", sarr);

If you're stuck using Java 7 or earlier with no libraries, you could write your own utility method:

Use with AIpublic static String myJoin(int[] arr, String separator) {
    if (null == arr || 0 == arr.length) return "";

    StringBuilder sb = new StringBuilder(256);
    sb.append(arr[0]);

    //if (arr.length == 1) return sb.toString();

    for (int i = 1; i < arr.length; i++) sb.append(separator).append(arr[i]);

    return sb.toString();
}

Then you can do:

Use with AIint[] arr = new int[] {1, 2, 3, 4, 5, 6, 7};
String result = myJoin(arr, " - ");
2 of 9
16

Java 8 Solution would be like this:

Use with AIStream.of(1,2,3,4).map(String::valueOf).collect(Collectors.joining("-"))
🌐
GeeksforGeeks
geeksforgeeks.org › java › ints-join-function-guava-java
Guava's Ints.join() Function in Java - GeeksforGeeks
July 11, 2025 - It provides a concise and readable way to join the elements of an int[] array into a delimited string. ... import com.google.common.primitives.Ints; import java.util.Arrays; class IntsJoinExample { public static void main(String[] args) { int[] a = { 2, 4, 6, 8, 10 }; // Using Ints.join() method to get a // string containing the elements of array // separated by a separator System.out.println(Ints.join(", ", a)); } }
🌐
Baeldung
baeldung.com › home › java › java string › array to string conversions
Array to String Conversions | Baeldung
September 16, 2026 - Additionally, we can use the Collectors.joining() method from the Java Streams API that joins strings from the Stream in the same order as its source array:
🌐
Blogger
javarevisited.blogspot.com › 2013 › 02 › combine-integer-and-string-array-java-example-tutorial.html
2 Ways to Combine Arrays in Java? Integer, String Array Copy Example
You can concatenate or combine two arrays of different lengths as shown in the second example, It's not necessary to be the same length but they must be of the same type, i.e. you can not combine the String array to int array in Java.
🌐
Medium
medium.com › @AlexanderObregon › javas-string-join-method-explained-77e1503095ec
Java’s String.join() Method Explained | Medium
September 2, 2024 - The String.join() method is one of the most useful utilities introduced in Java 8. It allows developers to combine a sequence of strings into a single string, with each element separated by a specified delimiter.
🌐
TutorialsPoint
tutorialspoint.com › ints-join-function-in-java
Ints join() function in Java
September 24, 2019 - JavaObject Oriented ProgrammingProgramming · The join() method of Ints class returns a string containing the supplied int values separated by separator. The syntax is as follows − · public static String join(String separator, int[] arr) Here, separator parameter is something that should ...
🌐
W3docs
w3docs.com › home › code snippets › java › how to convert an int array to string with tostring method in java
How to convert an int array to String with toString method in Java | W3docs
import java.util.Arrays; int[] array = {1, 2, 3, 4, 5}; String str = String.join(", ", Arrays.stream(array).mapToObj(String::valueOf).toArray(String[]::new)); // str is now "1, 2, 3, 4, 5" Copy · This code converts the array int array to a stream of strings, using the mapToObj() and String::valueOf methods.
Find elsewhere
🌐
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.
🌐
Scaler
scaler.com › home › topics › array to string in java
Array to String In Java | Scaler Topics
June 2, 2024 - We can use java stream API to convert an array to a string. In java 8 and above versions of java we have String.join() method which creates a new string by joining elements and separating them with a specified delimiter.
🌐
Edureka Community
edureka.co › home › community › categories › java › join array elements with a separator in java
Join array elements with a separator in Java | Edureka Community
August 16, 2018 - Is there a way to join an array, i.e. perform opposite operation of what split() does. Iterating ... do it but not able to find it. Please suggest.
🌐
Dot Net Perls
dotnetperls.com › join-java
Java - String.join Method - Dot Net Perls
January 25, 2024 - In a program, Strings are often separate. They are elements in an array, or just String variables in a method. With join() we merge them. In Java, the join method receives a variable number of arguments.
🌐
Mkyong
mkyong.com › home › java › java – how to join arrays
Java – How to join Arrays | mkyong.com
February 8, 2016 - package com.mkyong.example.array; import java.util.Arrays; import java.util.stream.IntStream; import java.util.stream.Stream; public class JoinArray { public static void main(String[] args) { String[] s1 = new String[]{"a", "b", "c"}; String[] s2 = new String[]{"d", "e", "f"}; String[] s3 = new String[]{"g", "h", "i"}; //join object type array String[] result = Stream.of(s1, s2, s3).flatMap(Stream::of).toArray(String[]::new); System.out.println(Arrays.toString(result)); int [] int1 = new int[]{1,2,3}; int[] int2 = new int[]{4,5,6}; int[] int3 = new int[]{7,8,9}; //join 2 primitive type array int[] result2 = IntStream.concat(Arrays.stream(int1), Arrays.stream(int2)).toArray(); //join 3 primitive type array, any better idea?
🌐
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 - The Syntax Breakdown There are two main ways to call it: Joining an Iterable (like a List or Set): String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) Joining an Array of elements: String join(CharSequence delimiter, ...
🌐
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 - Iterable which can be a list or array of elements, needs to be joined. It always returns a concatenated string of elements joined by the delimiter. import java.util.ArrayList; class Main { public static void main(String[] args) { ArrayList<String> arrayOfStrings = new ArrayList<>(); arrayOfStrings.add("Concatenating"); arrayOfStrings.add("the"); arrayOfStrings.add("array"); arrayOfStrings.add("list"); arrayOfStrings.add("elements"); arrayOfStrings.add("with"); arrayOfStrings.add("space"); arrayOfStrings.add("as"); arrayOfStrings.add("delimiter"); // joining arrayList with space between them as delimiter String joinedStr = String.join(" ", arrayOfStrings); System.out.println(joinedStr); } }
🌐
W3Schools
w3schools.com › java › ref_string_join.asp
Java String join() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... The join() method joins one or more strings with a specified separator.