Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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: 

[I@23fc4bec

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
asked Feb 7, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer
asked Feb 11, 2021 in Java by dante07 (13.1k points)

Browse Categories

...