{"id":65319,"date":"2025-05-03T12:05:02","date_gmt":"2025-05-03T04:05:02","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65319\/"},"modified":"2025-05-03T12:05:02","modified_gmt":"2025-05-03T04:05:02","slug":"java-%e5%ad%97%e7%ac%a6%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e8%b5%8b%e5%80%bc-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65319\/","title":{"rendered":"java \u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u8d4b\u503c"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u7ed9\u5b57\u7b26\u6570\u7ec4 (char[]) \u8d4b\u503c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a1. \u6570\u7ec4\u521d\u59cb\u5316\u5668\uff1a\u4f7f\u7528\u5927\u62ec\u53f7 ({}) \u548c\u9017\u53f7 (,)\uff0c\u76f4\u63a5\u4e3a\u6570\u7ec4\u8d4b\u503c\u3002 2. \u8d4b\u503c\u8fd0\u7b97\u7b26\uff1a\u4f7f\u7528\u8d4b\u503c\u8fd0\u7b97\u7b26 (=) \u5c06\u5355\u4e2a\u5b57\u7b26 (char) \u6216\u5b57\u7b26\u4e32 (string) \u8d4b\u503c\u7ed9\u6570\u7ec4\u5143\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111220212959700.jpg\" class=\"aligncenter\" title=\"java \u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u8d4b\u503c\u63d2\u56fe\" alt=\"java \u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u8d4b\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u5b57\u7b26\u6570\u7ec4\u8d4b\u503c<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u5b57\u7b26\u6570\u7ec4\uff08char[]\uff09\u662f\u7528\u4e8e\u5b58\u50a8\u5b57\u7b26\u5e8f\u5217\u7684\u6570\u636e\u7ed3\u6784\u3002\u8d4b\u503c\u7ed9\u5b57\u7b26\u6570\u7ec4\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668<\/strong><\/p>\n<p>\u4f7f\u7528\u5927\u62ec\u53f7 ({}) \u548c\u9017\u53f7 (,) \u5206\u9694\u5143\u7d20\uff0c\u53ef\u4ee5\u76f4\u63a5\u4e3a\u5b57\u7b26\u6570\u7ec4\u8d4b\u503c\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>char[] myArray = {'H', 'e', 'l', 'l', 'o'};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u597d\u5904\u662f\u7b80\u6d01\u660e\u4e86\uff0c\u9002\u5408\u5728\u58f0\u660e\u6570\u7ec4\u65f6\u76f4\u63a5\u8d4b\u503c\u3002<\/p>\n<p><strong>2. \u4f7f\u7528\u8d4b\u503c\u8fd0\u7b97\u7b26<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u8d4b\u503c\u8fd0\u7b97\u7b26 (=) \u5c06\u5355\u4e2a\u5b57\u7b26\uff08char\uff09\u6216\u5b57\u7b26\u4e32\uff08String\uff09\u8d4b\u503c\u7ed9\u5b57\u7b26\u6570\u7ec4\u7684\u5143\u7d20\uff1a<\/p>\n<pre>char[] myArray = new char[5];  \/\/ \u58f0\u660e\u4e00\u4e2a\u957f\u5ea6\u4e3a 5 \u7684\u5b57\u7b26\u6570\u7ec4\n\nmyArray[0] = 'H';  \/\/ \u8d4b\u503c\u5355\u4e2a\u5b57\u7b26\nmyArray[1] = 'e';\nmyArray[2] = 'l';\nmyArray[3] = 'l';\nmyArray[4] = 'o';\n\n\/\/ \u6216\u4f7f\u7528\u5b57\u7b26\u4e32\u8d4b\u503c\nString myString = \"Hello\";\nmyArray = myString.toCharArray();  \/\/ \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u597d\u5904\u662f\u53ef\u4ee5\u5728\u521b\u5efa\u6570\u7ec4\u540e\u6216\u5faa\u73af\u4e2d\u52a8\u6001\u5730\u8d4b\u503c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava \u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u8d4b\u503c\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>\u5728 java \u4e2d\uff0c\u7ed9\u5b57\u7b26\u6570\u7ec4 (char[]) \u8d4b\u503c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a1. \u6570\u7ec4\u521d\u59cb\u5316\u5668\uff1a\u4f7f\u7528\u5927\u62ec\u53f7 ({}) \u548c\u9017\u53f7 (,)\uff0c\u76f4\u63a5\u4e3a\u6570\u7ec4\u8d4b\u503c\u3002 2. \u8d4b\u503c\u8fd0\u7b97\u7b26\uff1a\u4f7f\u7528\u8d4b\u503c\u8fd0\u7b97\u7b26 (=) \u5c06\u5355\u4e2a\u5b57\u7b26 (char) \u6216\u5b57\u7b26\u4e32 (string) \u8d4b\u503c\u7ed9\u6570\u7ec4\u5143\u7d20\u3002 Java \u5b57\u7b26\u6570\u7ec4\u8d4b\u503c \u5728 Java \u4e2d\uff0c\u5b57\u7b26\u6570\u7ec4\uff08char[]\uff09\u662f\u7528\u4e8e\u5b58\u50a8\u5b57\u7b26\u5e8f\u5217\u7684\u6570\u636e\u7ed3\u6784\u3002\u8d4b\u503c\u7ed9\u5b57\u7b26\u6570\u7ec4\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a 1. \u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668 \u4f7f\u7528\u5927\u62ec\u53f7 ({}) \u548c\u9017\u53f7 (,) \u5206\u9694\u5143\u7d20\uff0c\u53ef\u4ee5\u76f4\u63a5\u4e3a\u5b57\u7b26\u6570\u7ec4\u8d4b\u503c\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b char[] myArray = {&#8216;H&#8217;, &#8216;e&#8217;, &#8216;l&#8217;, &#8216;l&#8217;, &#8216;o&#8217;}; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u79cd\u65b9\u6cd5\u7684\u597d\u5904\u662f\u7b80\u6d01\u660e\u4e86\uff0c\u9002\u5408\u5728\u58f0\u660e\u6570\u7ec4\u65f6\u76f4\u63a5\u8d4b\u503c\u3002 2. \u4f7f\u7528\u8d4b\u503c\u8fd0\u7b97\u7b26 \u53ef\u4ee5\u4f7f\u7528\u8d4b\u503c\u8fd0\u7b97\u7b26 (=) \u5c06\u5355\u4e2a\u5b57\u7b26\uff08char\uff09\u6216\u5b57\u7b26\u4e32\uff08String\uff09\u8d4b\u503c\u7ed9\u5b57\u7b26\u6570\u7ec4\u7684\u5143\u7d20\uff1a char[] myArray = new char[5]; \/\/ \u58f0\u660e\u4e00\u4e2a\u957f\u5ea6\u4e3a 5 \u7684\u5b57\u7b26\u6570\u7ec4 myArray[0] [&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-65319","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65319","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=65319"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65319\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}