Add java11-features module: runnable demos and captured output for the ankurm.com java11-features article
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
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() + "]");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user