What you want is the Arrays.toString(int[]) method:

import java.util.Arrays;

int[] array = new int[lnr.getLineNumber() + 1];
int i = 0;

..      

System.out.println(Arrays.toString(array));

There is a static Arrays.toString helper method for every different primitive java type; the one for int[] says this:

public static String toString(int[] a)

Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(int). Returns "null" if a is null.

Answer from Sbodd on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java string › array to string conversions
Array to String Conversions | Baeldung
September 16, 2026 - In this short tutorial, we’re going to look at converting an array of strings or integers to a string and back again. We can achieve this with vanilla Java and Java utility classes from commonly used libraries.
Discussions

Convert String to int array in java - Stack Overflow
I have one string: String arr = "[1,2]"; ie "[1,2]" is like a single String. How do I convert this arr to int array in java? More on stackoverflow.com
🌐 stackoverflow.com
reduce an array to string
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
6
1
October 17, 2021
Converting int[,] array to string[,] array?
static U[,] Convert(T[,] array, Func func) { var result = new U[array.GetLength(0), array.GetLength(1)]; for (int i = 0; i < array.GetLength(0); i++) for (int j = 0; j < array.GetLength(1); j++) { result[i, j] = func(array[i, j]); } return result; } More on reddit.com
🌐 r/csharp
7
0
July 24, 2020
Java- Converting a string of numbers separated by spaces into an array?
You have the right idea. String.split() will return an array of strings. Then, if you want to treat any individual string in that array as an integer you can use Integer.parseInt() . If you want to create an array of integers, just make the array that way. More on reddit.com
🌐 r/learnprogramming
7
4
February 2, 2016
🌐
GeeksforGeeks
geeksforgeeks.org › java › arrays-tostring-in-java-with-examples
Arrays.toString() in Java with Examples - GeeksforGeeks
Converts an array into a string containing all its elements. For object arrays with nested arrays, it prints memory references instead of actual values. For nested arrays, Arrays.deepToString() should be used to get full content representation.
Published: April 14, 2026
🌐
TutorialsPoint
tutorialspoint.com › java › util › arrays_tostring_int.htm
Java.util.Arrays.toString(int[ ]) Method
The java.util.Arrays.toString(int[]) method returns a string representation of the contents of the specified int array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]").
🌐
Techie Delight
techiedelight.com › home › java › convert int array to string array in java
Convert int array to string array in Java | Techie Delight
July 7, 2026 - Convert the specified primitive array to a IntStream using Arrays.stream() or IntStream.of() method. Convert each element of the stream to a string using IntStream.mapToObj() method.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-convert-an-array-to-string-in-java
How to Convert an Array to String in Java? - GeeksforGeeks
July 12, 2025 - // Java Program to convert an array to a string // using Arrays.toString() method import java.io.*; import java.util.Arrays; class GFG { public static void main(String[] args) { // create different types of arrays and // print their contents ...
🌐
Codemia
codemia.io › home › knowledge hub › 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 | Codemia
July 31, 2025 - Converting an integer array to a string representation is a common requirement when dealing with data display and logging. In Java, this can be accomplished using the toString method from the Java API. Although the toString method is not directly applicable to arrays, the Arrays utility class ...
🌐
CodeGym
codegym.cc › java blog › strings in java › array to string in java
Array to String in Java
November 27, 2023 - To make a whole array into a single string, you just loop through the array, using + to add each element to your string, and voilà – you get a big, nice string! Converting an array to string in Java doesn't have to be a head-scratcher.
🌐
iO Flood
ioflood.com › blog › array-to-string-java
Mastering Array to String Conversion in Java
February 27, 2024 - While converting arrays to strings in Java, you may encounter some common issues. Let’s discuss these problems and provide solutions and workarounds. A ‘NullPointerException’ can occur if you try to convert a null array to a string. Here’s an example: int[] array = null; String str = Arrays.toString(array); // Output: // 'java.lang.NullPointerException'
🌐
Hostman
hostman.com › tutorials › converting-arrays-and-strings-in-java
Java Array to String and String to Array Conversion Guide
Learn how to convert arrays to strings and strings to arrays in Java. Master the Arrays class, split() method, and manual conversion techniques.
🌐
Quora
quora.com › How-do-you-convert-an-integer-array-into-a-string-array-in-the-Java-programming-language
How to convert an integer array into a string array in the Java programming language - Quora
Answer: To convert an integer array into a string array in Java, you can iterate through each element of the integer array and convert each integer to its corresponding string representation. You can achieve this using the [code ]String.valueOf()[/code] method or by concatenating the integer with...
🌐
Scaler
scaler.com › home › topics › array to string in java
Array to String In Java | Scaler Topics
June 2, 2024 - In Java programming language, an array is a data structure that stores the same type of value in a contiguous memory location which we can access using the index, whereas a string is an object that stores a sequence of characters, so there can be some situation where we want to convert an array to string, so for this we have some methods like toString, StringBuilder append, etc.
🌐
Vultr Docs
docs.vultr.com › java › examples › convert int type variables to string
Java Program to convert int type variables to String | Vultr Docs
November 25, 2024 - ... int[] numbers = {10, 20, 30, 40}; String[] stringNumbers = Arrays.stream(numbers) .mapToObj(String::valueOf) .toArray(String[]::new); for (String s : stringNumbers) { System.out.println(s); }
🌐
freeCodeCamp
freecodecamp.org › news › how-to-convert-integer-to-string-in-java
Int to String in Java – How to Convert an Integer into a String
January 5, 2023 - You can convert variables from one data type to another in Java using different methods. In this article, you'll learn how to convert integers to strings in Java in the following ways: Using the Integer.toString() method. Using the String.valueOf(...
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-convert-an-array-to-string-in-java
How to convert an array to string in java?
March 11, 2026 - import java.util.Arrays; public class ArrayToString { public static void main(String args[]) throws Exception { int[] myArray = {23, 93, 56, 92, 39}; String str = Arrays.toString(myArray); System.out.println(str); } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › simplest-method-to-print-array-in-java
Simplest Method to Print Array in Java - GeeksforGeeks
July 23, 2025 - Interview Questions · Exercises · Examples · Quizzes · Projects · Cheatsheet · DSA in Java · Java Collection · Last Updated : 23 Jul, 2025 · Arrays.toString() Method of java.util.Arrays class is the simplest method to print an array in Java.
🌐
Reddit
reddit.com › r/javahelp › reduce an array to string
r/javahelp on Reddit: reduce an array to string
October 17, 2021 -

I come from a Ruby background, and am trying to get my feet wet using functional methods in Java. I'm having trouble understanding why the following example won't reduce an array of integers down to a string.

import java.util.Arrays;

import java.util.List;

import java.util.stream.*;

public class ReduceTest {
    public static void main(String[] args) {
	int[] numbers = {1,2,3,4,5};
	IntStream stream = [Arrays.stream](https://Arrays.stream)(numbers);
	String output = stream.reduce("",(int string, int number) -> string + Integer.toString(number));
    }
}

I'm getting the error:

The method reduce(int, IntBinaryOperator) in the type IntStream is not applicable for the arguments (String, (int string, int number) ->

{})

I don't understand why it's expecting an IntBinaryOperator, and don't really know what that is. From the examples I have seen, I would expect to pass a string to an accumulator.

Any thoughts/suggestions are appreciated, also would like to know the "Java" way of converting an array down to a string.

Top answer
1 of 2
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 2
1
What exactly would your expected output be here? Also please format that code.