0

Maybe I'm forgetting something, but I need a simple utility method to print the contents of any complex data structure involving Strings, rather than references, such as Enumeration<String>, HashMap<String,String[]>, etc.

It can include any combination of Arrays, Lists, Enumerations, etc.

e.g.:

HttpServletRequest request;
Enumeration<String> params = request.getParameters();
return params.toString(); 
// returns java.util.Collections$3@246f8103

or

Map<String,String[]> requestParamMap = request.getParameterMap();
return requestParamMap.toString(); 
// returns {function=[Ljava.lang.String;@4f9ffa55, jsessionId=[Ljava.lang.String;@4abf9318}
gene b.
  • 10,512
  • 21
  • 115
  • 227
  • 1
    Try to look here: http://stackoverflow.com/questions/443730/java-tostring-using-reflection – Firzen Dec 09 '15 at 21:27
  • weird, any collections should invoke content's `toString()`. and [String, should return a string](http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#toString--) – Bagus Tesa Dec 09 '15 at 21:28
  • 1
    If you use a `List` instead of an `Array`, the `Map` will print everything correctly. `Map>` – gonzo Dec 09 '15 at 21:35
  • There isn't an arbitrary way to do that for any complex data structure. – Louis Wasserman Dec 09 '15 at 21:48

0 Answers0