{"id":66977,"date":"2025-05-03T16:18:39","date_gmt":"2025-05-03T08:18:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66977\/"},"modified":"2025-05-03T16:18:39","modified_gmt":"2025-05-03T08:18:39","slug":"java%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e7%9a%84%e6%b1%89%e5%ad%97%e6%80%8e%e4%b9%88%e6%94%be%e5%9c%a8%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66977\/","title":{"rendered":"java\u5b57\u7b26\u4e32\u4e2d\u7684\u6c49\u5b57\u600e\u4e48\u653e\u5728\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u6c49\u5b57\u63d0\u53d6\u4e3a\u6570\u7ec4\uff1a\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff1b\u4f7f\u7528 unicode \u7801\uff1b\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff1b\u624b\u52a8\u904d\u5386\u5b57\u7b26\u4e32\u3002\u9009\u7528\u65b9\u6cd5\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u800c\u5b9a\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111721423993724.jpg\" class=\"aligncenter\" title=\"java\u5b57\u7b26\u4e32\u4e2d\u7684\u6c49\u5b57\u600e\u4e48\u653e\u5728\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u5b57\u7b26\u4e32\u4e2d\u7684\u6c49\u5b57\u600e\u4e48\u653e\u5728\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 Java \u5b57\u7b26\u4e32\u4e2d\u7684\u6c49\u5b57\u63d0\u53d6\u4e3a\u6570\u7ec4<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u6c49\u5b57\u63d0\u53d6\u4e3a\u6570\u7ec4\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a<\/strong><\/p>\n<pre>String str = \"\u4f60\u597d\uff0c\u4e16\u754c\";\nString[] hanziArray = str.split(\"[^\\u4E00-\\u9FA5]\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 Unicode \u7801\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String str = \"\u4f60\u597d\uff0c\u4e16\u754c\";\nList&lt;String&gt; hanziList = new ArrayList&lt;&gt;();\nfor (int i = 0; i &lt; str.length(); i++) {\n    int codePoint = str.codePointAt(i);\n    if (codePoint &gt;= 0x4E00 &amp;&amp; codePoint &lt;= 0x9FA5) {\n        hanziList.add(str.substring(i, i + 1));\n    }\n}\nString[] hanziArray = hanziList.toArray(new String[0]);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 Apache Commons Lang \u5e93\u4e2d\u7684 CharUtils.toList \u65b9\u6cd5\uff1a<\/p>\n<pre>String str = \"\u4f60\u597d\uff0c\u4e16\u754c\";\nString[] hanziArray = CharUtils.toList(str).stream()\n        .filter(ch -&gt; ch &gt;= 0x4E00 &amp;&amp; ch &lt;= 0x9FA5)\n        .map(ch -&gt; String.valueOf(ch))\n        .toArray(String[]::new);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u624b\u52a8\u904d\u5386\u5b57\u7b26\u4e32\uff1a<\/strong><\/p>\n<pre>String str = \"\u4f60\u597d\uff0c\u4e16\u754c\";\nString[] hanziArray = new String[str.length()];\nint count = 0;\nfor (int i = 0; i &lt; str.length(); i++) {\n    int codePoint = str.codePointAt(i);\n    if (codePoint &gt;= 0x4E00 &amp;&amp; codePoint &lt;= 0x9FA5) {\n        hanziArray[count++] = str.substring(i, i + 1);\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u5373\u53ef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u5b57\u7b26\u4e32\u4e2d\u7684\u6c49\u5b57\u600e\u4e48\u653e\u5728\u6570\u7ec4\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 java \u4e2d\uff0c\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u6c49\u5b57\u63d0\u53d6\u4e3a\u6570\u7ec4\uff1a\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff1b\u4f7f\u7528 unicode \u7801\uff1b\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff1b\u624b\u52a8\u904d\u5386\u5b57\u7b26\u4e32\u3002\u9009\u7528\u65b9\u6cd5\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u800c\u5b9a\u3002 \u5982\u4f55\u5c06 Java \u5b57\u7b26\u4e32\u4e2d\u7684\u6c49\u5b57\u63d0\u53d6\u4e3a\u6570\u7ec4 \u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u6c49\u5b57\u63d0\u53d6\u4e3a\u6570\u7ec4\uff1a 1. \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a String str = &#8220;\u4f60\u597d\uff0c\u4e16\u754c&#8221;; String[] hanziArray = str.split(&#8220;[^\\u4E00-\\u9FA5]&#8221;); \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 Unicode \u7801\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b String str = &#8220;\u4f60\u597d\uff0c\u4e16\u754c&#8221;; List&lt;String&gt; hanziList = new ArrayList&lt;&gt;(); for (int i = 0; i &lt; str.length(); i++) { int codePoint = str.codePointAt(i); if (codePoint &gt;= 0x4E00 &amp;&amp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-66977","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=66977"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66977\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}