0 votes
1 view
in Java by (9.5k points)

Below is the code I’ve to use toString(int[]) method

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

int i = 0;

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

This is the output I get: 

[[email protected]

It doesn’t give me the desired output as I want a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ``, " (a comma followed by a space). Can anyone tell me how to do this?

1 Answer

0 votes
by (19.7k points)

You have to use Arrays.toString(int[]) method for every different primitive java type: 

import java.util.Arrays;

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

int i = 0;

..      

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

Interested in Java? Check out this Java tutorial by Intellipaat. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 11 in Java by dante07 (13.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !

Categories

...