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());
}
Next »
Java String.valueOf()
« Previous
Java String.toUpperCase()
Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE
res – REST with Spring (eBook) (everywhere)
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.