Showing posts with label print. Show all posts
Showing posts with label print. Show all posts

December 31, 2014

Printing content of Java list

This is a very, very simple reference on how to print the contents of a Java List.  The idea is simple. I have a List and I want to loop over it and print whatever is stored in it. But do you really need to code a loop to do this?  Nope.  But I always forget how to correctly do it.  So here it is:

List< String > strings = new LinkedList< String >();
strings.add("one");
strings.add("two");
strings.add("three");

System.out.printf(
 "List< String >.toString()\n%s\n\n"
 ,strings.toString());
System.out.printf(
 "List< String >.toArray().toString()\n%s\n\n"
 ,strings.toArray().toString());
System.out.printf(
 "Arrays.toString(List< String >.toArray())\n%s\n\n"
 ,Arrays.toString(strings.toArray()));

The output looks like this:
List< String >.toString()
[one, two, three]

List< String >.toArray().toString()
[Ljava.lang.Object;@1ea87e7b

Arrays.toString(List< String >.toArray())
[one, two, three] 


Enjoy!


November 07, 2014

Servlet Info WebApp

Ferris Servlet Info WebApp is a simple servlet which dumps a bunch of info about the request, session, init-params, and server machine to the page for troubleshooting purposes.  It also includes an AJAX call back to the server which can be started and stopped with the "Start" and "Stop" buttons and how many seconds between AJAX calls is determined by the number in the input text box.  When the AJAX response is received, the data on the page is replaced by whatever the server sent back.  This WebApp is especially helpful troubleshooting clustered environments.

Clone the Mavenized project from GitHub (https://github.com/mjremijan/ferris-servletinfo). 

Here is what the information on the page looks like (IP address information has been blacked out)