{"id":38783,"date":"2024-11-26T10:06:46","date_gmt":"2024-11-26T02:06:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38783\/"},"modified":"2024-11-26T10:06:46","modified_gmt":"2024-11-26T02:06:46","slug":"string-%e6%80%8e%e4%b9%88%e8%bd%ac%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84-java","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38783\/","title":{"rendered":"string \u600e\u4e48\u8f6c\u5b57\u7b26\u4e32\u6570\u7ec4 java"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u53ef\u901a\u8fc7\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\uff1a\u4f7f\u7528 string.split() \u65b9\u6cd5\u6309\u7167\u6307\u5b9a\u5206\u9694\u7b26\u5206\u5272\u3002\u4f7f\u7528 stringtokenizer \u7c7b\u5206\u89e3\u5b57\u7b26\u4e32\u4e3a\u4ee4\u724c\uff0c\u518d\u4f7f\u7528 toarray() \u65b9\u6cd5\u8f6c\u6362\u4e3a\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111506243531102.jpg\" class=\"aligncenter\" title=\"string \u600e\u4e48\u8f6c\u5b57\u7b26\u4e32\u6570\u7ec4 java\u63d2\u56fe\" alt=\"string \u600e\u4e48\u8f6c\u5b57\u7b26\u4e32\u6570\u7ec4 java\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a<\/strong><\/p>\n<p>\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\u5728 Java \u4e2d\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u5728\u591a\u79cd\u573a\u666f\u4e2d\u4f7f\u7528\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u8f6c\u6362\u3002<\/p>\n<p><strong>1. \u4f7f\u7528 String.split() \u65b9\u6cd5<\/strong><\/p>\n<p>String.split() \u65b9\u6cd5\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u6309\u7167\u6307\u5b9a\u7684 delimiter \u5206\u5272\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002\u4f8b\u5982\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String myString = \"Hello, world, Java\";\nString[] words = myString.split(\",\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cmyString \u88ab\u6309\u7167\u9017\u53f7\u5206\u5272\uff0c\u7ed3\u679c\u5b58\u50a8\u5728 words \u6570\u7ec4\u4e2d\u3002<\/p>\n<p><strong>2. \u4f7f\u7528 StringTokenizer \u7c7b<\/strong><\/p>\n<p>StringTokenizer \u7c7b\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u6309\u7167\u6307\u5b9a\u7684 delimiter \u5206\u89e3\u6210 tokens\uff08\u5373\u5b57\u7b26\u4e32\uff09\u3002\u8981\u5c06 tokens \u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 toArray() \u65b9\u6cd5\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>String myString = \"Hello, world, Java\";\nStringTokenizer st = new StringTokenizer(myString, \",\");\nString[] words = st.toArray(new String[0]);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cmyString \u88ab\u6309\u7167\u9017\u53f7\u5206\u5272\uff0c\u7ed3\u679c\u5b58\u50a8\u5728 words \u6570\u7ec4\u4e2d\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4ee5\u4e0a\u4e24\u79cd\u65b9\u6cd5\u5728\u5904\u7406\u5305\u542b\u7279\u6b8a\u5b57\u7b26\uff08\u4f8b\u5982\u9017\u53f7\u6216\u7a7a\u683c\uff09\u7684\u5b57\u7b26\u4e32\u65f6\u53ef\u80fd\u9700\u8981\u8fdb\u884c\u989d\u5916\u7684\u5904\u7406\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u8981\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fstring \u600e\u4e48\u8f6c java\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>java \u4e2d\u53ef\u901a\u8fc7\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\uff1a\u4f7f\u7528 string.split() \u65b9\u6cd5\u6309\u7167\u6307\u5b9a\u5206\u9694\u7b26\u5206\u5272\u3002\u4f7f\u7528 stringtokenizer \u7c7b\u5206\u89e3\u5b57\u7b26\u4e32\u4e3a\u4ee4\u724c\uff0c\u518d\u4f7f\u7528 toarray() \u65b9\u6cd5\u8f6c\u6362\u4e3a\u6570\u7ec4\u3002 Java \u4e2d\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\u5728 Java \u4e2d\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u5728\u591a\u79cd\u573a\u666f\u4e2d\u4f7f\u7528\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u8f6c\u6362\u3002 1. \u4f7f\u7528 String.split() \u65b9\u6cd5 String.split() \u65b9\u6cd5\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u6309\u7167\u6307\u5b9a\u7684 delimiter \u5206\u5272\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002\u4f8b\u5982\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b String myString = &#8220;Hello, world, Java&#8221;; String[] words = myString.split(&#8220;,&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0cmyString \u88ab\u6309\u7167\u9017\u53f7\u5206\u5272\uff0c\u7ed3\u679c\u5b58\u50a8\u5728 words \u6570\u7ec4\u4e2d\u3002 2. \u4f7f\u7528 StringTokenizer \u7c7b StringTokenizer \u7c7b\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u6309\u7167\u6307\u5b9a\u7684 delimiter \u5206\u89e3\u6210 tokens\uff08\u5373\u5b57\u7b26\u4e32\uff09\u3002\u8981\u5c06 tokens \u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 toArray() \u65b9\u6cd5\u3002\u4f8b\u5982\uff1a String myString = &#8220;Hello, world, [&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-38783","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38783","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=38783"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38783\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}