{"id":66013,"date":"2025-05-03T13:55:44","date_gmt":"2025-05-03T05:55:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66013\/"},"modified":"2025-05-03T13:55:44","modified_gmt":"2025-05-03T05:55:44","slug":"java%e4%b8%ad%e7%9a%84%e5%af%b9%e8%b1%a1%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\/66013\/","title":{"rendered":"java\u4e2d\u7684\u5bf9\u8c61\u6570\u7ec4\u600e\u4e48\u8d4b\u503c"},"content":{"rendered":"<blockquote><p>\n  \u5bf9\u8c61\u6570\u7ec4\u8d4b\u503c\u6b65\u9aa4\uff1a\u521b\u5efa\u6307\u5b9a\u7c7b\u578b\u7684\u5bf9\u8c61\u6570\u7ec4\u3002\u4f7f\u7528\u4e0b\u6807\u64cd\u4f5c\u7b26\u4e3a\u5143\u7d20\u8d4b\u503c\u3002\u6ce8\u610f\uff1a\u6570\u7ec4\u5927\u5c0f\u56fa\u5b9a\uff0c\u5143\u7d20\u5f15\u7528\u5b9e\u9645\u5bf9\u8c61\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/14\/2024111411102817609.jpg\" class=\"aligncenter\" title=\"java\u4e2d\u7684\u5bf9\u8c61\u6570\u7ec4\u600e\u4e48\u8d4b\u503c\u63d2\u56fe\" alt=\"java\u4e2d\u7684\u5bf9\u8c61\u6570\u7ec4\u600e\u4e48\u8d4b\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u5bf9\u8c61\u6570\u7ec4\u7684\u8d4b\u503c<\/strong><\/p>\n<p>Java \u4e2d\uff0c\u5bf9\u8c61\u6570\u7ec4\u7684\u8d4b\u503c\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u6570\u7ec4\u5bf9\u8c61<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u6307\u5b9a\u7c7b\u578b\u7684\u5bf9\u8c61\u6570\u7ec4\uff1aObject[] arr = new Object[size];\uff0c\u5176\u4e2d size \u4e3a\u6570\u7ec4\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8d4b\u503c\u5143\u7d20<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\u4f7f\u7528\u4e0b\u6807\u64cd\u4f5c\u7b26 ([]) \u4e3a\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\uff1aarr[index] = value;\uff0c\u5176\u4e2d index \u662f\u5143\u7d20\u4e0b\u6807\uff0cvalue \u662f\u8981\u8d4b\u4e88\u7684\u503c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a Object \u6570\u7ec4\nObject[] arr = new Object[3];\n\n\/\/ \u8d4b\u503c\u5143\u7d20\narr[0] = \"Hello\";\narr[1] = 10;\narr[2] = new Person(\"John\", 25);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u6570\u7ec4\u5143\u7d20\u662f\u5f15\u7528\u7c7b\u578b\uff08\u4f8b\u5982 Person\uff09\uff0c\u5219\u5b9e\u9645\u8d4b\u503c\u7684\u662f\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u5bf9\u8c61\u672c\u8eab\u3002<\/li>\n<li>\u6570\u7ec4\u5927\u5c0f\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u80fd\u66f4\u6539\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 length \u5c5e\u6027\u83b7\u53d6\u6570\u7ec4\u7684\u957f\u5ea6\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 Arrays.toString() \u65b9\u6cd5\u6253\u5370\u6570\u7ec4\u5185\u5bb9\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u9664\u4e86\u4f7f\u7528\u4e0b\u6807\u64cd\u4f5c\u7b26\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5bf9\u5bf9\u8c61\u6570\u7ec4\u8d4b\u503c\uff1a<\/p>\n<ul>\n<li>\n<p><strong>for \u5faa\u73af<\/strong><\/p>\n<ul>\n<li>\n<p>\u904d\u5386\u6570\u7ec4\u5e76\u4f9d\u6b21\u8d4b\u503c\uff1a<\/p>\n<pre>for (int i = 0; i &lt; arr.length; i++) {\n arr[i] = value;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u76f4\u63a5\u521d\u59cb\u5316<\/strong><\/p>\n<ul>\n<li>\n<p>\u5728\u521b\u5efa\u6570\u7ec4\u65f6\u76f4\u63a5\u521d\u59cb\u5316\u5143\u7d20\uff1a<\/p>\n<pre>Object[] arr = new Object[] { \"Hello\", 10, new Person(\"John\", 25) };<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e2d\u7684\u5bf9\u8c61\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>\u5bf9\u8c61\u6570\u7ec4\u8d4b\u503c\u6b65\u9aa4\uff1a\u521b\u5efa\u6307\u5b9a\u7c7b\u578b\u7684\u5bf9\u8c61\u6570\u7ec4\u3002\u4f7f\u7528\u4e0b\u6807\u64cd\u4f5c\u7b26\u4e3a\u5143\u7d20\u8d4b\u503c\u3002\u6ce8\u610f\uff1a\u6570\u7ec4\u5927\u5c0f\u56fa\u5b9a\uff0c\u5143\u7d20\u5f15\u7528\u5b9e\u9645\u5bf9\u8c61\u3002 Java \u4e2d\u5bf9\u8c61\u6570\u7ec4\u7684\u8d4b\u503c Java \u4e2d\uff0c\u5bf9\u8c61\u6570\u7ec4\u7684\u8d4b\u503c\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u521b\u5efa\u6570\u7ec4\u5bf9\u8c61 \u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u6307\u5b9a\u7c7b\u578b\u7684\u5bf9\u8c61\u6570\u7ec4\uff1aObject[] arr = new Object[size];\uff0c\u5176\u4e2d size \u4e3a\u6570\u7ec4\u5927\u5c0f\u3002 \u8d4b\u503c\u5143\u7d20 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4f7f\u7528\u4e0b\u6807\u64cd\u4f5c\u7b26 ([]) \u4e3a\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\uff1aarr[index] = value;\uff0c\u5176\u4e2d index \u662f\u5143\u7d20\u4e0b\u6807\uff0cvalue \u662f\u8981\u8d4b\u4e88\u7684\u503c\u3002 \u793a\u4f8b\uff1a \/\/ \u521b\u5efa\u4e00\u4e2a Object \u6570\u7ec4 Object[] arr = new Object[3]; \/\/ \u8d4b\u503c\u5143\u7d20 arr[0] = &#8220;Hello&#8221;; arr[1] = 10; arr[2] = new Person(&#8220;John&#8221;, 25); \u767b\u5f55\u540e\u590d\u5236 \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff1a \u5982\u679c\u6570\u7ec4\u5143\u7d20\u662f\u5f15\u7528\u7c7b\u578b\uff08\u4f8b\u5982 Person\uff09\uff0c\u5219\u5b9e\u9645\u8d4b\u503c\u7684\u662f\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u5bf9\u8c61\u672c\u8eab\u3002 \u6570\u7ec4\u5927\u5c0f\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u80fd\u66f4\u6539\u3002 \u53ef\u4ee5\u4f7f\u7528 length [&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-66013","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66013","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=66013"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66013\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}