Wednesday, March 26, 2008

ArrayUtils.toString(Object[] array)

While programming in Java, I needed a quick way to write out the contents of an array of Objects in java (Object[]), eg. using

logger.debug("result: " + list);

where list is a Object[], results in an unreadable

result: [[Ljava.lang.Object;@5a49e6]


The trick is to use:

logger.debug("result: " + ArrayUtils.toString(list));

where ArrayUtils is a class of the (already mentioned before) Jakarta commons-lang library.

No comments: