How to convert an int array to String with toString method in Java -


this question has answer here:

i using trying use tostring(int[]) method, think doing wrong:

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/arrays.html#tostring(int[])

my code:

int[] array = new int[lnr.getlinenumber() + 1]; int = 0;  system.out.println(array.tostring()); 

the output is:

[i@23fc4bec 

also tried printing this, but:

system.out.println(new string().tostring(array));  // **error on next line** method tostring() in type string not applicable arguments (int[]) 

i took code out of bigger , more complex code, can add if needed. should give general information.

i looking output, in oracle's documentation:

the string representation consists of list of array's elements, enclosed in square brackets ("[]"). adjacent elements separated characters ", " (a comma followed space).

what want arrays.tostring(int[]) method:

import java.util.arrays;  int[] array = new int[lnr.getlinenumber() + 1]; int = 0;  ..        system.out.println(arrays.tostring(array)); 

there static arrays.tostring helper method every different primitive java type; 1 int[] says this:

public static string tostring(int[] a) 

returns string representation of contents of specified array. string representation consists of list of array's elements, enclosed in square brackets ("[]"). adjacent elements separated characters ", " (a comma followed space). elements converted strings string.valueof(int). returns "null" if a null.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -