Holly Cummins

Java basics: converting a collection to a string

2012-09-27 holly cumminsjava

If you look up how to write a map or a list out as a string, you can find lots of complicated answers involving loops and even XMLEncoders. It doesn’t have to be that hard. The easiest way to convert a Map into a nice string?

String niceString = Arrays.toString(map.entrySet().toArray());

It’s even easier for a list:

String niceString = Arrays.toString(list.toArray());

Ta-daaa!

Loading...
Holly Cummins

Holly Cummins. Holly Cummins is a Senior Technical Staff Member and Innovation Leader at IBM. Holly has used technology to enable innovation, for clients across a range of industries, from banking to catering to retail to NGOs. During her time as a lead developer in the IBM Garage, she has led projects to count fish, help a blind athlete run ultra-marathons in the desert solo, improve health care for the elderly, and change how city parking works. Holly is also an Oracle Java Champion, IBM Q Ambassador, and JavaOne Rock Star. Before joining the IBM Garage, she was Delivery Lead for the WebSphere Liberty Profile (now Open Liberty). Holly co-authored Manning’s Enterprise OSGi in Action and is a regular keynote speaker. She is an active speaker and has spoken at KubeCon (keynote), GOTO, JavaOne, Devoxx, Sonar+D, JavaZone, JFokus, The ServerSide Java Symposium, GOTO, JAX London, QCon, GeeCon, and the Great Indian Developer Summit, as well as a number of user groups.