{"id":39509,"date":"2024-11-26T09:19:50","date_gmt":"2024-11-26T01:19:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39509\/"},"modified":"2024-11-26T09:19:50","modified_gmt":"2024-11-26T01:19:50","slug":"java%e6%80%8e%e4%b9%88%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%be%93%e5%85%a5%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39509\/","title":{"rendered":"Java\u600e\u4e48\u5c06\u5b57\u7b26\u4e32\u8f93\u5165\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u5c06\u5b57\u7b26\u4e32\u8f93\u5165\u6570\u7ec4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u5b57\u7b26\u4e32\u62c6\u5206\u65b9\u6cd5\uff1a\u901a\u8fc7\u4f20\u5165\u5206\u9694\u7b26\u8c03\u7528 string.split() \u65b9\u6cd5\uff0c\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4ee5\u5206\u9694\u7b26\u4e3a\u754c\u9650\u7684\u5b50\u4e32\u5e76\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002\u4f7f\u7528\u5b57\u7b26\u6570\u7ec4\uff1a\u8c03\u7528 string.tochararray() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4f5c\u4e3a\u4e00\u4e2a\u5143\u7d20\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111611582144210.jpg\" class=\"aligncenter\" title=\"Java\u600e\u4e48\u5c06\u5b57\u7b26\u4e32\u8f93\u5165\u6570\u7ec4\u63d2\u56fe\" alt=\"Java\u600e\u4e48\u5c06\u5b57\u7b26\u4e32\u8f93\u5165\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>Java\u4e2d\u5c06\u5b57\u7b26\u4e32\u8f93\u5165\u6570\u7ec4<\/strong><\/p>\n<p><strong>\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>Java\u4e2d\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f93\u5165\u6570\u7ec4\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u5b57\u7b26\u4e32\u62c6\u5206\u65b9\u6cd5<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String[] words = \"Hello Java\".split(\" \");  \/\/ \u4ee5\u7a7a\u683c\u4f5c\u4e3a\u5206\u9694\u7b26<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528\u5b57\u7b26\u6570\u7ec4<\/strong><\/p>\n<pre>char[] chars = \"Hello Java\".toCharArray();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8be6\u7ec6\u8bf4\u660e\uff1a<\/strong><\/p>\n<p><strong>1. \u5b57\u7b26\u4e32\u62c6\u5206\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>\u8c03\u7528 String.split() \u65b9\u6cd5\uff0c\u4f20\u5165\u5206\u9694\u7b26\u4f5c\u4e3a\u53c2\u6570\u3002<\/li>\n<li>\u5206\u9694\u7b26\u53ef\u4ee5\u662f\u4efb\u4f55\u5b57\u7b26\u6216\u5b57\u7b26\u4e32\uff0c\u5b83\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4ee5\u5206\u9694\u7b26\u4e3a\u754c\u9650\u7684\u5b50\u4e32\u3002<\/li>\n<li>\u7ed3\u679c\u5b58\u50a8\u5728\u4e2d\u3002<\/li>\n<\/ul>\n<p><strong>2. \u4f7f\u7528\u5b57\u7b26\u6570\u7ec4\uff1a<\/strong><\/p>\n<ul>\n<li>\u8c03\u7528 String.toCharArray() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002<\/li>\n<li>\u6bcf\u4e2a\u5b57\u7b26\u4f5c\u4e3a\u4e00\u4e2a\u5143\u7d20\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>String sentence = \"Java Programming Language\";\n\n\/\/ \u4f7f\u7528\u5b57\u7b26\u4e32\u62c6\u5206\u65b9\u6cd5\nString[] words = sentence.split(\" \");\nfor (String word : words) {\n    System.out. println(word);\n}\n\n\/\/ \u4f7f\u7528\u5b57\u7b26\u6570\u7ec4\nchar[] characters = sentence.toCharArray();\nfor (char character : characters) {\n    System.out. println(character);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>Java\nProgramming\nLanguage\n\nJ\na\nv\na\nP\nr\no\ng\nr\na\nm\nm\ni\nn\ng\nL\na\nn\ng\nu\na\ng\ne<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava\u600e\u4e48\u5c06\u5b57\u7b26\u4e32\u8f93\u5165\u6570\u7ec4\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\u5c06\u5b57\u7b26\u4e32\u8f93\u5165\u6570\u7ec4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u5b57\u7b26\u4e32\u62c6\u5206\u65b9\u6cd5\uff1a\u901a\u8fc7\u4f20\u5165\u5206\u9694\u7b26\u8c03\u7528 string.split() \u65b9\u6cd5\uff0c\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4ee5\u5206\u9694\u7b26\u4e3a\u754c\u9650\u7684\u5b50\u4e32\u5e76\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002\u4f7f\u7528\u5b57\u7b26\u6570\u7ec4\uff1a\u8c03\u7528 string.tochararray() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4f5c\u4e3a\u4e00\u4e2a\u5143\u7d20\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002 Java\u4e2d\u5c06\u5b57\u7b26\u4e32\u8f93\u5165\u6570\u7ec4 \u65b9\u6cd5\uff1a Java\u4e2d\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f93\u5165\u6570\u7ec4\uff1a 1. \u4f7f\u7528\u5b57\u7b26\u4e32\u62c6\u5206\u65b9\u6cd5 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b String[] words = &#8220;Hello Java&#8221;.split(&#8221; &#8220;); \/\/ \u4ee5\u7a7a\u683c\u4f5c\u4e3a\u5206\u9694\u7b26 \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528\u5b57\u7b26\u6570\u7ec4 char[] chars = &#8220;Hello Java&#8221;.toCharArray(); \u767b\u5f55\u540e\u590d\u5236 \u8be6\u7ec6\u8bf4\u660e\uff1a 1. \u5b57\u7b26\u4e32\u62c6\u5206\u65b9\u6cd5\uff1a \u8c03\u7528 String.split() \u65b9\u6cd5\uff0c\u4f20\u5165\u5206\u9694\u7b26\u4f5c\u4e3a\u53c2\u6570\u3002 \u5206\u9694\u7b26\u53ef\u4ee5\u662f\u4efb\u4f55\u5b57\u7b26\u6216\u5b57\u7b26\u4e32\uff0c\u5b83\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u4ee5\u5206\u9694\u7b26\u4e3a\u754c\u9650\u7684\u5b50\u4e32\u3002 \u7ed3\u679c\u5b58\u50a8\u5728\u4e2d\u3002 2. \u4f7f\u7528\u5b57\u7b26\u6570\u7ec4\uff1a \u8c03\u7528 String.toCharArray() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002 \u6bcf\u4e2a\u5b57\u7b26\u4f5c\u4e3a\u4e00\u4e2a\u5143\u7d20\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002 \u793a\u4f8b\uff1a String sentence = &#8220;Java Programming Language&#8221;; \/\/ \u4f7f\u7528\u5b57\u7b26\u4e32\u62c6\u5206\u65b9\u6cd5 String[] words = [&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-39509","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39509","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=39509"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39509\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}