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.
🌐
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 › 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
🌐
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.
🌐
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 ...
Find elsewhere
🌐
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.
🌐
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.
🌐
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...
🌐
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); }
🌐
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.
🌐
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.
🌐
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(...