{"id":38449,"date":"2024-11-26T09:04:45","date_gmt":"2024-11-26T01:04:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38449\/"},"modified":"2024-11-26T09:04:45","modified_gmt":"2024-11-26T01:04:45","slug":"java%e5%ad%97%e7%ac%a6%e5%88%86%e5%89%b2%e6%88%90%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e6%9c%80%e5%bf%ab","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38449\/","title":{"rendered":"java\u5b57\u7b26\u5206\u5272\u6210\u6570\u7ec4\u600e\u4e48\u6700\u5feb"},"content":{"rendered":"<blockquote><p>\n  \u6700\u5feb\u7684 java \u5b57\u7b26\u5206\u5272\u6210\u6570\u7ec4\u7684\u65b9\u6cd5\u662f\uff1a1. string.split()\uff0c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5f15\u64ce\uff1b2. stringtokenizer\uff0c\u4f7f\u7528\u5b57\u7b26\u5206\u9694\u5668\u3002string.split() \u901a\u5e38\u5728\u7b80\u5355\u5206\u9694\u60c5\u51b5\u4e0b\u66f4\u5feb\u901f\uff0c\u800c stringtokenizer \u9002\u7528\u4e8e\u5b57\u7b26\u5206\u9694\u6216\u590d\u6742\u6a21\u5f0f\u5339\u914d\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111502001992287.jpg\" class=\"aligncenter\" title=\"java\u5b57\u7b26\u5206\u5272\u6210\u6570\u7ec4\u600e\u4e48\u6700\u5feb\u63d2\u56fe\" alt=\"java\u5b57\u7b26\u5206\u5272\u6210\u6570\u7ec4\u600e\u4e48\u6700\u5feb\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u5c06\u5b57\u7b26\u5206\u5272\u6210\u6570\u7ec4\u7684\u6700\u5feb\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u5c06\u5b57\u7b26\u5206\u5272\u6210\u6570\u7ec4\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u4f46\u6700\u5feb\u7684\u901a\u5e38\u662f\u4ee5\u4e0b\u65b9\u6cd5\u4e4b\u4e00\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1aString.split()<\/strong><\/p>\n<pre>String[] arr = str.split(\",\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>split() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u7531\u5206\u9694\u7b26\u5206\u5272\u7684\u8f93\u5165\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u65b9\u6cd5 2\uff1aStringTokenizer<\/strong><\/p>\n<pre>StringTokenizer tokenizer = new StringTokenizer(str, \",\");\nString[] arr = new String[tokenizer.countTokens()];\nint i = 0;\nwhile (tokenizer.hasMoreTokens()) {\n    arr[i++] = tokenizer.nextToken();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>StringTokenizer \u7c7b\u63d0\u4f9b\u4e86\u4e00\u79cd\u89e3\u6790\u5b57\u7b26\u4e32\u5e76\u5c06\u5176\u5206\u6210\u6807\u8bb0\u7684\u65b9\u6cd5\u3002<\/p>\n<p><strong>\u6027\u80fd\u6bd4\u8f83<\/strong><\/p>\n<p>\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0cString.split() \u65b9\u6cd5\u6bd4 StringTokenizer \u66f4\u5feb\u3002\u8fd9\u662f\u56e0\u4e3a String.split() \u5728\u5185\u90e8\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5f15\u64ce\uff0c\u800c StringTokenizer \u5219\u4f7f\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u5b57\u7b26\u5206\u9694\u5668\u3002<\/p>\n<p><strong>\u6700\u4f73\u5b9e\u8df5<\/strong><\/p>\n<ul>\n<li>\u5bf9\u4e8e\u7b80\u5355\u7684\u5206\u9694\uff0cString.split() \u901a\u5e38\u662f\u6700\u4f73\u9009\u62e9\u3002<\/li>\n<li>\u5982\u679c\u5206\u9694\u7b26\u662f\u4e00\u4e2a\u5b57\u7b26\u6216\u8005\u9700\u8981\u66f4\u590d\u6742\u7684\u6a21\u5f0f\u5339\u914d\uff0c\u5219\u53ef\u4ee5\u8003\u8651 StringTokenizer\u3002<\/li>\n<li>\u5bf9\u4e8e\u975e\u5e38\u5927\u7684\u5b57\u7b26\u4e32\uff0c\u8fd8\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 Stream API \u6216\u81ea\u5b9a\u4e49\u89e3\u6790\u5668\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u5b57\u7b26\u5206\u5272\u6210\u6570\u7ec4\u600e\u4e48\u6700\u5feb\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u5feb\u7684 java \u5b57\u7b26\u5206\u5272\u6210\u6570\u7ec4\u7684\u65b9\u6cd5\u662f\uff1a1. string.split()\uff0c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5f15\u64ce\uff1b2. stringtokenizer\uff0c\u4f7f\u7528\u5b57\u7b26\u5206\u9694\u5668\u3002string.split() \u901a\u5e38\u5728\u7b80\u5355\u5206\u9694\u60c5\u51b5\u4e0b\u66f4\u5feb\u901f\uff0c\u800c stringtokenizer \u9002\u7528\u4e8e\u5b57\u7b26\u5206\u9694\u6216\u590d\u6742\u6a21\u5f0f\u5339\u914d\u3002 Java \u4e2d\u5c06\u5b57\u7b26\u5206\u5272\u6210\u6570\u7ec4\u7684\u6700\u5feb\u65b9\u6cd5 \u5728 Java \u4e2d\uff0c\u5c06\u5b57\u7b26\u5206\u5272\u6210\u6570\u7ec4\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u4f46\u6700\u5feb\u7684\u901a\u5e38\u662f\u4ee5\u4e0b\u65b9\u6cd5\u4e4b\u4e00\uff1a \u65b9\u6cd5 1\uff1aString.split() String[] arr = str.split(&#8220;,&#8221;); \u767b\u5f55\u540e\u590d\u5236 split() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u7531\u5206\u9694\u7b26\u5206\u5272\u7684\u8f93\u5165\u5b57\u7b26\u4e32\u7ec4\u6210\u7684\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u65b9\u6cd5 2\uff1aStringTokenizer StringTokenizer tokenizer = new StringTokenizer(str, &#8220;,&#8221;); String[] arr = new String[tokenizer.countTokens()]; int i = 0; while (tokenizer.hasMoreTokens()) { arr[i++] = tokenizer.nextToken(); } \u767b\u5f55\u540e\u590d\u5236 StringTokenizer \u7c7b\u63d0\u4f9b\u4e86\u4e00\u79cd\u89e3\u6790\u5b57\u7b26\u4e32\u5e76\u5c06\u5176\u5206\u6210\u6807\u8bb0\u7684\u65b9\u6cd5\u3002 \u6027\u80fd\u6bd4\u8f83 \u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0cString.split() \u65b9\u6cd5\u6bd4 StringTokenizer \u66f4\u5feb\u3002\u8fd9\u662f\u56e0\u4e3a [&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-38449","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38449","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=38449"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38449\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}