This is a fairly simple question. When you print out a LinkedList, like so:
System.out.println(list);
It prints it out, surrounding the list in square brackets like this:
[thing 1, thing 2, thing 3]
Is there a way I can print it out without the square brackets?
Yes – iterate the list and print it (with comma after each, but the last element). However, there are utils to help:
Guava:
commons-lang:
And one note: don’t rely on the
.toString()method of any object. It is not meant for displaying the object to users, or to be used as a predefined format – it is meant mainly for debugging purposes.