Among other changes, JDK 11 introduces 6 new methods for java.lang.String class:
repeat(int) - Repeats the String as many times as provided by the
Here is a unit-test that illustrates the answer by @MikhailKholodkov, using Java 11.
(Note that \u2000 is above \u0020 and not considered whitespace by trim())
public class StringTestCase {
@Test
public void testSame() {
String s = "\t abc \n";
assertEquals("abc", s.trim());
assertEquals("abc", s.strip());
}
@Test
public void testDifferent() {
Character c = '\u2000';
String s = c + "abc" + c;
assertTrue(Character.isWhitespace(c));
assertEquals(s, s.trim());
assertEquals("abc", s.strip());
}
}