How many spaces will Java String.trim() remove?

oneat picture oneat · Feb 4, 2010 · Viewed 246k times · Source

In Java, I have a String like this:

"     content     ".

Will String.trim() remove all spaces on these sides or just one space on each?

Answer

LukeH picture LukeH · Feb 4, 2010

All of them.

Returns: A copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.

~ Quoted from Java 1.5.0 docs

(But why didn't you just try it and see for yourself?)