16 lines
897 B
Java
16 lines
897 B
Java
import java.util.stream.Collectors;
|
|
|
|
/** The String additions in Java 11: isBlank, lines, strip, repeat. */
|
|
public class StringMethods {
|
|
public static void main(String[] args) {
|
|
String em = String.valueOf((char) 0x2003); // EM SPACE: whitespace to strip(), not to trim()
|
|
String padded = em + " hello " + em;
|
|
System.out.println("trim() length : " + padded.trim().length());
|
|
System.out.println("strip() length : " + padded.strip().length());
|
|
System.out.println("isBlank(\" \") : " + " ".isBlank() + " isEmpty: " + " ".isEmpty());
|
|
System.out.println("lines() : " + "a\nb\r\nc".lines().collect(Collectors.toList()));
|
|
System.out.println("repeat(3) : " + "ab".repeat(3));
|
|
System.out.println("stripLeading : [" + " x ".stripLeading() + "] stripTrailing: [" + " x ".stripTrailing() + "]");
|
|
}
|
|
}
|