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

public String trim()

Example

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