{"id":65714,"date":"2025-05-03T08:35:19","date_gmt":"2025-05-03T00:35:19","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65714\/"},"modified":"2025-05-03T08:35:19","modified_gmt":"2025-05-03T00:35:19","slug":"java%e7%9a%84%e5%ad%97%e7%ac%a6%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%ae%9a%e4%b9%89-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65714\/","title":{"rendered":"java\u7684\u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49"},"content":{"rendered":"<blockquote><p>\n  \u5b57\u7b26\u6570\u7ec4\u662f\u5b58\u50a8\u5b57\u7b26\u5e8f\u5217\u7684 java \u6570\u636e\u7ed3\u6784\u3002\u5b83\u662f\u4e00\u4e2a char \u7c7b\u578b\u7684\u4e00\u7ef4\u6570\u7ec4\uff1a\u521b\u5efa\uff1achar[] arrayname = new char[size];\u8bbf\u95ee\u5143\u7d20\uff1achars[index]\uff1b\u7279\u70b9\uff1a\u56fa\u5b9a\u5927\u5c0f\u3001\u7d22\u5f15\u4ece 0 \u5f00\u59cb\u3001\u8d85\u51fa\u754c\u9650\u629b\u51fa\u5f02\u5e38\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111307574433185.jpg\" class=\"aligncenter\" title=\"java\u7684\u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49\u63d2\u56fe\" alt=\"java\u7684\u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5b9a\u4e49 Java \u4e2d\u7684\u5b57\u7b26\u6570\u7ec4<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u5b57\u7b26\u6570\u7ec4\u662f\u4e00\u79cd\u7528\u6765\u5b58\u50a8\u5b57\u7b26\u5e8f\u5217\u7684\u6570\u636e\u7ed3\u6784\u3002\u5b83\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a char \u7c7b\u578b\u7684\u5b57\u7b26\u3002<\/p>\n<p><strong>\u5b9a\u4e49\u5b57\u7b26\u6570\u7ec4\u7684\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>char[] arrayName = new char[size];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>arrayName \u662f\u6570\u7ec4\u7684\u540d\u79f0\u3002<\/li>\n<li>size \u662f\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u5373\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6570\u91cf\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a chars \u7684\u5b57\u7b26\u6570\u7ec4\uff0c\u5176\u4e2d\u5305\u542b 5 \u4e2a\u5143\u7d20\uff1a<\/p>\n<pre>char[] chars = new char[5];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u6765\u8bbf\u95ee\u548c\u64cd\u4f5c\u6570\u7ec4\u4e2d\u7684\u5b57\u7b26\uff1a<\/p>\n<pre>\/\/ \u5728\u7d22\u5f15 0 \u5904\u5b58\u50a8\u5b57\u7b26 'a'\nchars[0] = 'a';\n\n\/\/ \u83b7\u53d6\u7d22\u5f15 2 \u5904\u7684\u5b57\u7b26\nchar c = chars[2];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>Java \u4e2d\u7684\u5b57\u7b26\u6570\u7ec4\u662f\u56fa\u5b9a\u5927\u5c0f\u7684\uff0c\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u80fd\u66f4\u6539\u5176\u5927\u5c0f\u3002<\/li>\n<li>\u7d22\u5f15\u4ece 0 \u5f00\u59cb\uff0c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u4e3a size &#8211; 1\u3002<\/li>\n<li>\u5982\u679c\u5c1d\u8bd5\u8bbf\u95ee\u8d85\u51fa\u6570\u7ec4\u754c\u9650\u7684\u7d22\u5f15\uff0c\u4f1a\u629b\u51fa IndexOutOfBoundsException\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u7684\u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49\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>\u5b57\u7b26\u6570\u7ec4\u662f\u5b58\u50a8\u5b57\u7b26\u5e8f\u5217\u7684 java \u6570\u636e\u7ed3\u6784\u3002\u5b83\u662f\u4e00\u4e2a char \u7c7b\u578b\u7684\u4e00\u7ef4\u6570\u7ec4\uff1a\u521b\u5efa\uff1achar[] arrayname = new char[size];\u8bbf\u95ee\u5143\u7d20\uff1achars[index]\uff1b\u7279\u70b9\uff1a\u56fa\u5b9a\u5927\u5c0f\u3001\u7d22\u5f15\u4ece 0 \u5f00\u59cb\u3001\u8d85\u51fa\u754c\u9650\u629b\u51fa\u5f02\u5e38\u3002 \u5982\u4f55\u5b9a\u4e49 Java \u4e2d\u7684\u5b57\u7b26\u6570\u7ec4 \u5728 Java \u4e2d\uff0c\u5b57\u7b26\u6570\u7ec4\u662f\u4e00\u79cd\u7528\u6765\u5b58\u50a8\u5b57\u7b26\u5e8f\u5217\u7684\u6570\u636e\u7ed3\u6784\u3002\u5b83\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a char \u7c7b\u578b\u7684\u5b57\u7b26\u3002 \u5b9a\u4e49\u5b57\u7b26\u6570\u7ec4\u7684\u8bed\u6cd5\uff1a char[] arrayName = new char[size]; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b arrayName \u662f\u6570\u7ec4\u7684\u540d\u79f0\u3002 size \u662f\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u5373\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6570\u91cf\u3002 \u793a\u4f8b\uff1a \u4ee5\u4e0b\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a chars \u7684\u5b57\u7b26\u6570\u7ec4\uff0c\u5176\u4e2d\u5305\u542b 5 \u4e2a\u5143\u7d20\uff1a char[] chars = new char[5]; \u767b\u5f55\u540e\u590d\u5236 \u73b0\u5728\uff0c\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u6765\u8bbf\u95ee\u548c\u64cd\u4f5c\u6570\u7ec4\u4e2d\u7684\u5b57\u7b26\uff1a \/\/ \u5728\u7d22\u5f15 0 \u5904\u5b58\u50a8\u5b57\u7b26 &#8216;a&#8217; chars[0] = &#8216;a&#8217;; \/\/ \u83b7\u53d6\u7d22\u5f15 [&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-65714","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65714","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=65714"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65714\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}