Skip to content
Advertisement

Equivalent of PHP’s print_r in Java?

last time I asked how to populate a data structure here. Now I would like to know if there’s something in Java, like the print_r I use in PHP, to represent what I have populated in the Maps and lists without having to do my own algorithm.

Any ideas?

Advertisement

Answer

Calling toString on the collection should return a string containing all the elements string representations.

This won’t work with built-in arrays though, as they don’t have a toString override and will just give you a memory address.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement