Java String.trim()

The method trim() removes any whitespace at the beginning and at the end of a String. If the String contains only spaces, then the method returns an empty String.

Available Signatures

[source,java,gutter:,false]

public String trim()

Example

[source,java,gutter:,true]

@Test
public void whenTrim_thenCorrect() {
    assertEquals("foo", " foo  ".trim());
}