1

I have an object array from a Hibernate query that I want to show in a logger message.

I have

//row output
for (Object[] objs : results) 
{
    logger.info(objs.toString());
} 

but I get [Ljava.lang.Object;@60cf75a9 for each.

How do I convert the array to a string output?

earcam
  • 6,662
  • 4
  • 37
  • 57
user2568374
  • 1,164
  • 4
  • 11
  • 21

2 Answers2

4

Don't use the .toString() method of Object[]. Use Arrays.toString()

for (Object[] objs : results) 
{
    logger.info( Arrays.toString( objs ) );
} 
dsh
  • 12,037
  • 3
  • 33
  • 51
  • That's it thanks. I tried Arrays.toString before and got syntax errors, think i used it with a String.format(). Your example works. – user2568374 Aug 13 '15 at 19:29
0

You need to over-ride the toString method to suit your needs. Right now it's printing out the memory address of each object in the array.

public String toString() {
//              Return whatever aspect of the object you want to display.
}
Jon Snow
  • 230
  • 1
  • 9