JDK 12版本包括對Unicode 11.0.0的支持。在發佈支持Unicode 10.0.0的JDK 11以後,Unicode 11.0.0引
入瞭如下JDK 12中包含的新功能:
684 new characters
11 new blocks
7 new scripts.
其中:
684個新字符,包含如下重要內容:
66個表情符號字符(66 emoji characters)
Copyleft符號(Copyleft symbol)
評級系統的半星(Half stars for rating systems)
額外的占星符號(Additional astrological symbols)
象棋中國象棋符號(Xiangqi Chinese chess symbols)
7個新腳本:
Hanifi Rohingya
Old Sogdian
Sogdian
Dogra
Gunjala Gondi
Makasar
Medefaidrin
11個新塊,包括上面列出的新腳本的7個塊和如下現有腳本的4個塊:
格魯吉亞擴展(Georgian Extended)
瑪雅數字(Mayan Numerals)
印度Siyaq數字(Indic Siyaq Numbers)
國際象棋符號(Chess Symbols)java
NumberFormat 添加了對以緊湊形式格式化數字的支持。安全
@Test public void testCompactNumberFormat(){ 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)); }
輸出異步
1萬 2萬 100萬 11億 1兆 1126兆
var result = "foo" .transform(input -> input + " bar") .transform(String::toUpperCase) System.out.println(result); // FOO BAR
private static void testIndent() { System.out.println("======test java 12 indent======"); String result = "Java\n Python\nC++".indent(3); System.out.println(result); }
public void testFilesMismatch() throws IOException { FileWriter fileWriter = new FileWriter("tmp\\a.txt"); fileWriter.write("a"); fileWriter.write("b"); fileWriter.write("c"); fileWriter.close(); FileWriter fileWriterB = new FileWriter("tmp\\b.txt"); fileWriterB.write("a"); fileWriterB.write("1"); fileWriterB.write("c"); fileWriterB.close(); System.out.println(Files.mismatch(Path.of("tmp/a.txt"),Path.of("tmp/b.txt"))); }