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

java - Convert int array to string variable - Stack Overflow
I have an integer array that keeps binary numbers 0 and 1 in itself. I want to convert my integer array to a string variable in java. How can I do it? More on stackoverflow.com
🌐 stackoverflow.com
November 21, 2012
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
How to put a string into an array of integer?
Is it because the array can only ever contain integers? Yes. If you want an array that can contain more than one class, you could try Object[]. But... what are you up to? Maybe we can help. Sometimes a little bit of the "why" can help a great deal with the "what". More on reddit.com
🌐 r/javahelp
19
0
December 1, 2025
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 ("[]").
🌐
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 ...
Find elsewhere
🌐
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 ...
🌐
Baeldung
baeldung.com › home › java › java streams › mapping an array of integers to strings using java streams
Mapping an Array of Integers to Strings Using Java Streams | Baeldung
January 8, 2024 - Another potential use case is converting our integer array into a single String. We can reuse much of the above code for this along with Stream.collect() to reduce the Stream into a String. The collect() method is versatile and lets us terminate our Streams into a wide range of types.
🌐
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'
🌐
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.
🌐
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.
🌐
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); }
🌐
YouTube
youtube.com › watch
String Array To String || Integer Array To Integer || Mini Java Interview Questions Series - YouTube
String Array To String || Integer Array To Integer || Mini Java Interview Questions SeriesSchedule a meeting in case of any queries/guidance/counselling:http...
Published: July 29, 2022