switch语句

class Haha {
public static void main(String[] args) throws IOException, InterruptedException {
    var day = 2;
    switch (day) {
        case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);
        case TUESDAY -> System.out.println(7);
        case THURSDAY, SATURDAY -> System.out.println(8);
        case WEDNESDAY -> System.out.println(9);
    }
}
}
switch也可以用作语句
System.out.println(switch (day) {
    case MONDAY, FRIDAY, SUNDAY -> 6;
    case TUESDAY -> 7;
    case THURSDAY, SATURDAY -> 8;
    case WEDNESDAY -> 9;
    default -> -1;
});


数字转字符串NumberFormat

var cnf = NumberFormat.getCompactNumberInstance(Locale.CHINA, NumberFormat.Style.SHORT);
System.out.println(cnf.format(1_0000));
System.out.println(cnf.format(1_9200));
System.out.println(cnf.format(1_000_000));
System.out.println(cnf.format(1L << 30));
System.out.println(cnf.format(1L << 40));
System.out.println(cnf.format(1L << 50));
System.out.println(NumberFormat.getCompactNumberInstance(Locale.CHINA, NumberFormat.Style.SHORT).format(12345));
System.out.println(NumberFormat.getCompactNumberInstance(Locale.CHINA, NumberFormat.Style.LONG).format(12345));

String的成员函数非常多

transform
java @Test public void testStringTransform(){ System.out.println("hello".transform(new Function<String, Integer>() { @Override public Integer apply(String s) { return s.hashCode(); } })); } 
indent

@Test
public void testStringIndent(){
    System.out.println("hello".indent(3));
}

其它

JDK12放弃了对jdk6及其以前版本的支持。