{"id":64337,"date":"2025-05-03T11:34:44","date_gmt":"2025-05-03T03:34:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64337\/"},"modified":"2025-05-03T11:34:44","modified_gmt":"2025-05-03T03:34:44","slug":"%e6%80%8e%e4%b9%88%e6%8a%8a%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%8f%98%e6%88%90%e6%95%b0%e7%bb%84java-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64337\/","title":{"rendered":"\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u53d8\u6210\u6570\u7ec4JAVA"},"content":{"rendered":"<blockquote><p>\n  \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\u6709\u56db\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 split() \u65b9\u6cd5\u6839\u636e\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 tochararray() \u65b9\u6cd5\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002\u4f7f\u7528 stringjoiner \u7c7b\u8fde\u63a5\u5b57\u7b26\u4e32\u5e76\u4f7f\u7528\u8fde\u63a5\u7b26\u5206\u5272\u3002\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u5b57\u7b26\u4e32\u5e76\u5b58\u50a8\u5339\u914d\u7ed3\u679c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/03\/2024110305392832883.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u53d8\u6210\u6570\u7ec4JAVA\u63d2\u56fe\" alt=\"\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u53d8\u6210\u6570\u7ec4JAVA\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u7ec4\uff08Java\uff09<\/strong><\/p>\n<p>\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u7ec4\u5728 Java \u4e2d\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\uff1a<\/p>\n<p><strong>\u4f7f\u7528 split() \u65b9\u6cd5<\/strong><\/p>\n<p>split() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u6839\u636e\u6307\u5b9a\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u6210\u4e00\u4e2a\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u5c06\u5b57\u7b26\u4e32 &#8220;a,b,c&#8221; \u8f6c\u6362\u4e3a\u6570\u7ec4\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String[] array = \"a,b,c\".split(\",\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 toCharArray() \u65b9\u6cd5<\/strong><\/p>\n<p>toCharArray() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u4e00\u4e2a\u5b57\u7b26\u6570\u7ec4\u3002\u6bcf\u4e2a\u5b57\u7b26\u5bf9\u5e94\u4e8e\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>char[] array = \"abc\".toCharArray();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 StringJoiner<\/strong><\/p>\n<p>StringJoiner \u7c7b\u53ef\u4ee5\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u8fde\u63a5\u8d77\u6765\uff0c\u5e76\u4f7f\u7528\u6307\u5b9a\u7684\u8fde\u63a5\u7b26\u3002\u4f8b\u5982\uff0c\u5c06\u5b57\u7b26\u4e32\u5217\u8868 [&#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;] \u8f6c\u6362\u4e3a\u6570\u7ec4\uff1a<\/p>\n<pre>StringJoiner joiner = new StringJoiner(\",\");\njoiner.add(\"a\").add(\"b\").add(\"c\");\nString[] array = joiner.toString().split(\",\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong><\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7528\u6765\u5206\u5272\u5b57\u7b26\u4e32\uff0c\u5e76\u5c06\u5176\u5339\u914d\u7684\u7ed3\u679c\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002\u4f8b\u5982\uff0c\u5c06 HTML \u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u6807\u7b7e\u8f6c\u6362\u4e3a\u6570\u7ec4\uff1a<\/p>\n<pre>String html = \"&lt;p&gt;Hello&lt;\/p&gt;&lt;p&gt;World&lt;\/p&gt;\";\nString[] array = html.split(\"&lt;p&gt;|&lt;\/p&gt;\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u9700\u6c42\u3002\u5982\u679c\u5b57\u7b26\u4e32\u9700\u8981\u6839\u636e\u7279\u5b9a\u7684\u6a21\u5f0f\u5206\u5272\uff0c\u5219\u4f7f\u7528 split() \u65b9\u6cd5\u66f4\u5408\u9002\u3002\u5982\u679c\u9700\u8981\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\uff0c\u5219\u4f7f\u7528 toCharArray() \u65b9\u6cd5\u3002\u5bf9\u4e8e\u9700\u8981\u8fde\u63a5\u591a\u4e2a\u5b57\u7b26\u4e32\u7684\u60c5\u51b5\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528 StringJoiner \u7c7b\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u53d8\u6210\u6570\u7ec4JAVA\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>\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\u6709\u56db\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 split() \u65b9\u6cd5\u6839\u636e\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 tochararray() \u65b9\u6cd5\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002\u4f7f\u7528 stringjoiner \u7c7b\u8fde\u63a5\u5b57\u7b26\u4e32\u5e76\u4f7f\u7528\u8fde\u63a5\u7b26\u5206\u5272\u3002\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u5b57\u7b26\u4e32\u5e76\u5b58\u50a8\u5339\u914d\u7ed3\u679c\u3002 \u5982\u4f55\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u7ec4\uff08Java\uff09 \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u7ec4\u5728 Java \u4e2d\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\uff1a \u4f7f\u7528 split() \u65b9\u6cd5 split() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u6839\u636e\u6307\u5b9a\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u5272\u6210\u4e00\u4e2a\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u5c06\u5b57\u7b26\u4e32 &#8220;a,b,c&#8221; \u8f6c\u6362\u4e3a\u6570\u7ec4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b String[] array = &#8220;a,b,c&#8221;.split(&#8220;,&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 toCharArray() \u65b9\u6cd5 toCharArray() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u4e00\u4e2a\u5b57\u7b26\u6570\u7ec4\u3002\u6bcf\u4e2a\u5b57\u7b26\u5bf9\u5e94\u4e8e\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u3002\u4f8b\u5982\uff1a char[] array = &#8220;abc&#8221;.toCharArray(); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 StringJoiner StringJoiner \u7c7b\u53ef\u4ee5\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u8fde\u63a5\u8d77\u6765\uff0c\u5e76\u4f7f\u7528\u6307\u5b9a\u7684\u8fde\u63a5\u7b26\u3002\u4f8b\u5982\uff0c\u5c06\u5b57\u7b26\u4e32\u5217\u8868 [&#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;] \u8f6c\u6362\u4e3a\u6570\u7ec4\uff1a StringJoiner joiner = new StringJoiner(&#8220;,&#8221;); joiner.add(&#8220;a&#8221;).add(&#8220;b&#8221;).add(&#8220;c&#8221;); String[] array = joiner.toString().split(&#8220;,&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f \u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7528\u6765\u5206\u5272\u5b57\u7b26\u4e32\uff0c\u5e76\u5c06\u5176\u5339\u914d\u7684\u7ed3\u679c\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002\u4f8b\u5982\uff0c\u5c06 [&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-64337","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64337","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=64337"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64337\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}