{"id":1944,"date":"2021-10-07T23:34:39","date_gmt":"2021-10-07T15:34:39","guid":{"rendered":"https:\/\/199604.com\/?p=1944"},"modified":"2021-10-07T23:34:39","modified_gmt":"2021-10-07T15:34:39","slug":"%e4%bb%8ejava-8%e5%88%b0-java-17-java-11","status":"publish","type":"post","link":"https:\/\/199604.com\/1944","title":{"rendered":"\u4eceJava 8\u5230 Java 17&#8211;Java 11"},"content":{"rendered":"<p>Java 11\u662f\u8fd9\u662f Java \u5927\u7248\u672c\u5468\u671f\u53d8\u5316\u540e\u7684\u7b2c\u4e00\u4e2a\u957f\u671f\u652f\u6301\u7248\u672c\uff08LTS\u7248\u672c\uff0cLong-Term-Support\uff0c\u6301\u7eed\u652f\u6301\u52302026\u5e749\u6708\uff09\uff0c\u662f\u76ee\u524d\u5168\u7403\u4f7f\u7528\u6700\u591a\u7684LTS\u7248\u672c\u4e4b\u4e00\u3002<\/p>\n<p>\u5b98\u65b9\u65b0\u7279\u6027\uff1a<\/p>\n<ul>\n<li>\u672c\u5730\u53d8\u91cf\u7c7b\u578b<\/li>\n<li>\u5b57\u7b26\u4e32\u52a0\u5f3a<\/li>\n<li>\u96c6\u5408\u52a0\u5f3a<\/li>\n<li>\u52a0\u5f3a\u6587\u4ef6\u8bfb\u5199<\/li>\n<\/ul>\n<h2>\u672c\u5730\u53d8\u91cf\u7c7b\u578b<\/h2>\n<p>\u8fd9\u4e2a\u65b0\u529f\u80fd\u662fjava10\u4e3aJava\u589e\u52a0\u4e00\u4e9b\u8bed\u6cd5\u7cd6 &#8211; \u7b80\u5316\u5b83\u5e76\u6539\u5584\u5f00\u53d1\u8005\u4f53\u9a8c<\/p>\n<pre><code class=\"language-java line-numbers\">        var str = \"Hello Java11\";\n        \/\/\u7b49\u4ef7\u4e8e String str = \"Hello Java11\";\n        System.out.print(str); \/\/ Hello Java11\n<\/code><\/pre>\n<h2>\u5b57\u7b26\u4e32API\u589e\u5f3a<\/h2>\n<p>Java11\u65b0\u589e\u4e86\u4e00\u4e9b\u5b57\u7b26\u4e32\u7684\u5904\u7406\u65b9\u6cd5\uff0c\u907f\u514d\u6211\u4eec\u5728\u5f88\u5e38\u89c1\u7684\u573a\u666f\u4e2d\u5f15\u5165\u989d\u5916\u7684\u3001\u590d\u6742\u7684API\u3002<\/p>\n<h3>isBlank()<\/h3>\n<p>\u7528\u6765\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u4e0d\u662f\u7a7a\u5b57\u7b26<code>\"\"<\/code>\u6216\u8005<code>trim()<\/code>\u4e4b\u540e(<code>\" \"<\/code>)\u4e3a\u7a7a\u5b57\u7b26:<\/p>\n<pre><code class=\"language-java line-numbers\">        String blankStr = \" \";\n        \/\/ true\n        System.out.println(\"blankStr.isBlank():\"+blankStr.isBlank());\n<\/code><\/pre>\n<h3>lines()<\/h3>\n<p>\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u6309\u7167\u884c\u7ec8\u6b62\u7b26\uff08\u6362\u884c\u7b26<code>\\n<\/code>\u6216\u8005\u56de\u8f66\u7b26<code>\\r<\/code>\uff09\u8fdb\u884c\u5206\u5272\uff0c\u5e76\u5c06\u5206\u5272\u4e3a<code>Stream<\/code>\u6d41:<\/p>\n<pre><code class=\"language-java line-numbers\">        var str = \"A\\nB\\nC\";\n        Stream&lt;String&gt; lines = str.lines();\n        lines.forEach(System.out::println);\n\/\/ a b c \n<\/code><\/pre>\n<h3>strip()<\/h3>\n<p>\u53bb\u9664\u5b57\u7b26\u4e32\u524d\u540e\u7684\u201c\u5168\u89d2\u548c\u534a\u89d2\u201d\u7a7a\u767d\u5b57\u7b26<\/p>\n<ol>\n<li><code>strip()<\/code> \u5220\u9664\u5b57\u7b26\u4e32\u5934\u5c3e\u7684\u6240\u6709\u7a7a\u767d\u7b26<\/li>\n<li><code>stripLeading()<\/code>  \u5220\u9664\u5b57\u7b26\u4e32\u5de6\u8fb9 ( \u5934\u90e8 ) \u7684\u6240\u6709\u7a7a\u767d\u7b26<\/li>\n<li><code>stripTrailing()<\/code>\u5220\u9664\u5b57\u7b26\u4e32\u53f3\u8fb9 ( \u5c3e\u90e8 ) \u7684\u6240\u6709\u7a7a\u767d\u7b26<\/li>\n<\/ol>\n<p><code>trim()<\/code>\u65b9\u6cd5\uff0c\u4ece\u4e0b\u9762\u4e5f\u770b\u51fa\u6765\u4e86\u5dee\u522b\uff0c<code>trim()<\/code>\u53ea\u80fd\u53bb\u9664<code>\u534a\u89d2<\/code>\u7a7a\u767d\u7b26\u3002\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">        var str = \" Java11 \";\n        System.out.println(\"-\" + str.strip() + \"-\");\n        System.out.println(\"-\" + str.stripLeading() + \"-\");\n        System.out.println(\"-\" + str.stripTrailing() + \"-\");\n        System.out.println(\"-\" + str.trim() + \"-\");\n\n        str = \"Java11\\u3000\";\n        System.out.println(\"str = \" + str.length());\n        System.out.println(\"trim = \" + str.trim().length());\n        System.out.println(\"strip = \" + str.strip().length());\n<\/code><\/pre>\n<h3>repeat(n)<\/h3>\n<p>\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u91cd\u590d\u6307\u5b9a\u6b21\u6570\uff0c\u5982\u679c\u4f20\u9012\u7684\u662f\u8d1f\u6570\uff0c\u5219\u4f1a\u629b\u51fa\u5f02\u5e38\uff0c\u5982\u679c\u4f20\u9012\u7684\u662f 0 \uff0c\u90a3\u4e48\u5c31\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u4e86<\/p>\n<p><code>System.out.println(\"Java11\".repeat(3)); \/\/ Java11Java11Java11<\/code><\/p>\n<h2><strong>\u96c6\u5408\u52a0\u5f3a<\/strong><\/h2>\n<h3>Collection.toArray(IntFunction)<\/h3>\n<p>\u5728java.util.Collection\u63a5\u53e3\u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e2a\u65b0\u7684\u9ed8\u8ba4\u65b9\u6cd5toArray\uff08IntFunction\uff09\u3002\u6b64\u65b9\u6cd5\u5141\u8bb8\u5c06\u96c6\u5408\u7684\u5143\u7d20\u4f20\u8f93\u5230\u65b0\u521b\u5efa\u7684\u6240\u9700\u8fd0\u884c\u65f6\u7c7b\u578b\u7684\u6570\u7ec4\u3002<\/p>\n<pre><code class=\"language-java line-numbers\">        var list = List.of(\"Java\", \"Python\", \"C\");\n        String[] array = list.toArray(String[]::new);\n        for (String s : array) {\n            System.out.println(\"s:\"+s);\n        }\n<\/code><\/pre>\n<h2>\u52a0\u5f3a\u6587\u4ef6\u8bfb\u5199<\/h2>\n<p>Java 11\u4e2d\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u548c\u5199\u5165\u5b57\u7b26\u4e32\u5185\u5bb9\u4e86\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>Files<\/code>\u5de5\u5177\u7c7b\u63d0\u4f9b\u7684\u65b0\u7684\u9759\u6001\u65b9\u6cd5<code>readString<\/code>\u548c<code>writeString<\/code>\u5206\u522b\u8fdb\u884c\u8bfb\u5199\u6587\u4ef6\u7684\u5b57\u7b26\u4e32\u5185\u5bb9\u3002<\/p>\n<pre><code class=\"language-java line-numbers\">        String dir= \"E:\/\/test_test\";\n        \/\/ \u5199\u5165\u6587\u4ef6\n        Files.writeString(Path.of(\"E:\/\/test_test\/\/hello.txt\"),\"hello java 11\");\n        \/\/ \u8bfb\u53d6\u6587\u4ef6\n        String fileContent = Files.readString(Path.of(\"E:\/\/test_test\/\/hello.txt\"));\n        System.out.println(\"fileContent:\"+fileContent);\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Java 11\u662f\u8fd9\u662f Java \u5927\u7248\u672c\u5468\u671f\u53d8\u5316\u540e\u7684\u7b2c\u4e00\u4e2a\u957f\u671f\u652f\u6301\u7248\u672c\uff08LTS\u7248\u672c\uff0cLong-Term-Supp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[292,130],"tags":[129],"class_list":{"0":"post-1944","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-java","8":"tag-java"},"_links":{"self":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/1944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/comments?post=1944"}],"version-history":[{"count":1,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/1944\/revisions"}],"predecessor-version":[{"id":1945,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/1944\/revisions\/1945"}],"wp:attachment":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/media?parent=1944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/categories?post=1944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/tags?post=1944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}