{"id":66484,"date":"2025-05-03T09:25:54","date_gmt":"2025-05-03T01:25:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66484\/"},"modified":"2025-05-03T09:25:54","modified_gmt":"2025-05-03T01:25:54","slug":"java%e6%80%8e%e4%b9%88%e6%8a%8a%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%ac%e6%8d%a2%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66484\/","title":{"rendered":"java\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u6709\u4e09\u79cd\u65b9\u6cd5\u5c06 java \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\uff1a\u4f7f\u7528 split() \u65b9\u6cd5\u6839\u636e\u5206\u9694\u7b26\u62c6\u5206\u5b57\u7b26\u4e32\uff1b\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5b9a\u4e49\u6a21\u5f0f\u5339\u914d\u5b57\u7b26\u4e32\u4e2d\u7684\u7279\u5b9a\u90e8\u5206\uff1b\u4f7f\u7528 stringtokenizer \u7c7b\u6307\u5b9a\u5206\u9694\u7b26\u5e76\u5ffd\u7565\u8fde\u7eed\u7684\u5206\u9694\u7b26\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111604452180758.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 Java \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u65b9\u6cd5\uff1a\u4f7f\u7528 split()<\/strong><\/p>\n<p>split() \u65b9\u6cd5\u662f\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\u6700\u7b80\u5355\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u5b83\u6839\u636e\u7ed9\u5b9a\u7684\u5206\u9694\u7b26\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u6210\u591a\u4e2a\u90e8\u5206\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>String str = \"Hello,world,Java\";\nString[] arr = str.split(\",\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>arr \u73b0\u5728\u5305\u542b\u4ee5\u4e0b\u5143\u7d20\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>arr[0] = &#8220;Hello&#8221;<\/li>\n<li>arr[1] = &#8220;world&#8221;<\/li>\n<li>arr[2] = &#8220;Java&#8221;<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong><\/p>\n<p>\u53e6\u4e00\u79cd\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u6a21\u5f0f\uff0c\u7528\u4e8e\u5339\u914d\u5b57\u7b26\u4e32\u4e2d\u7684\u7279\u5b9a\u90e8\u5206\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>String str = \"Hello world Java\";\nString[] arr = str.split(\"\\s+\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u91cc\uff0c&#8221;s+&#8221; \u5339\u914d\u4e00\u4e2a\u6216\u591a\u4e2a\u7a7a\u683c\uff0c\u56e0\u6b64 arr \u5c06\u5305\u542b\u4ee5\u4e0b\u5143\u7d20\uff1a<\/p>\n<ul>\n<li>arr[0] = &#8220;Hello&#8221;<\/li>\n<li>arr[1] = &#8220;world&#8221;<\/li>\n<li>arr[2] = &#8220;Java&#8221;<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528 StringTokenizer<\/strong><\/p>\n<p>StringTokenizer \u7c7b\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u590d\u6742\u7684\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\u7684\u65b9\u6cd5\u3002\u5b83\u5141\u8bb8\u60a8\u6307\u5b9a\u5206\u9694\u7b26\uff0c\u8fd8\u53ef\u4ee5\u5ffd\u7565\u8fde\u7eed\u7684\u5206\u9694\u7b26\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>String str = \"Hello,,world,Java\";\nStringTokenizer st = new StringTokenizer(str, \",\");\nwhile (st.hasMoreTokens()) {\n  System.out.println(st.nextToken());\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u5c06\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<ul>\n<li>Hello<\/li>\n<li>world<\/li>\n<li>Java<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\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>\u6709\u4e09\u79cd\u65b9\u6cd5\u5c06 java \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\uff1a\u4f7f\u7528 split() \u65b9\u6cd5\u6839\u636e\u5206\u9694\u7b26\u62c6\u5206\u5b57\u7b26\u4e32\uff1b\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5b9a\u4e49\u6a21\u5f0f\u5339\u914d\u5b57\u7b26\u4e32\u4e2d\u7684\u7279\u5b9a\u90e8\u5206\uff1b\u4f7f\u7528 stringtokenizer \u7c7b\u6307\u5b9a\u5206\u9694\u7b26\u5e76\u5ffd\u7565\u8fde\u7eed\u7684\u5206\u9694\u7b26\u3002 \u5982\u4f55\u5c06 Java \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4 \u76f4\u63a5\u65b9\u6cd5\uff1a\u4f7f\u7528 split() split() \u65b9\u6cd5\u662f\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\u6700\u7b80\u5355\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u5b83\u6839\u636e\u7ed9\u5b9a\u7684\u5206\u9694\u7b26\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u6210\u591a\u4e2a\u90e8\u5206\u3002\u4f8b\u5982\uff1a String str = &#8220;Hello,world,Java&#8221;; String[] arr = str.split(&#8220;,&#8221;); \u767b\u5f55\u540e\u590d\u5236 arr \u73b0\u5728\u5305\u542b\u4ee5\u4e0b\u5143\u7d20\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b arr[0] = &#8220;Hello&#8221; arr[1] = &#8220;world&#8221; arr[2] = &#8220;Java&#8221; \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f \u53e6\u4e00\u79cd\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u6a21\u5f0f\uff0c\u7528\u4e8e\u5339\u914d\u5b57\u7b26\u4e32\u4e2d\u7684\u7279\u5b9a\u90e8\u5206\u3002\u4f8b\u5982\uff1a String str = &#8220;Hello world Java&#8221;; String[] arr = str.split(&#8220;\\s+&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u91cc\uff0c&#8221;s+&#8221; \u5339\u914d\u4e00\u4e2a\u6216\u591a\u4e2a\u7a7a\u683c\uff0c\u56e0\u6b64 arr \u5c06\u5305\u542b\u4ee5\u4e0b\u5143\u7d20\uff1a arr[0] = &#8220;Hello&#8221; [&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-66484","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66484","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=66484"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66484\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}