Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invocation of toString on an array - FindBugs

I am getting the below Findbugs error for my code,

Invocation of toString on <<Package Path>>

 The code invokes toString on an array, which will generate a fairly useless
 result such as [C@16f0472. Consider using Arrays.toString to convert the
 array into a readable String that gives the contents of the array.
 See Programming Puzzlers, chapter 3, puzzle 12. 

Code:

logger.info("Adding information"+ Employee.getName()+ " "+
            employeeForm.getQuestionAndAnswers());

Please let me know what is the error.

like image 681
Srinivasan Avatar asked Jul 18 '11 04:07

Srinivasan


People also ask

How do you use toString in an array?

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 ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space).

How do you Stringify an array in Java?

The three methods demonstrated for getting a String out of these three types of arrays are (1) simple Object. toString() on each array (implicitly in case of null array to avoid the dreaded NullPointerException), (2) Arrays. toString(Object[]) , and (3) Arrays. deepToString(Object[]) .


1 Answers

As it says, doing

myArray.toString()

will generate something useless like java.lang.int[]@45345262

you'd want to use

Arrays.toString(myArray);
like image 187
MeBigFatGuy Avatar answered Sep 28 '22 06:09

MeBigFatGuy