{"id":38142,"date":"2024-11-26T13:39:25","date_gmt":"2024-11-26T05:39:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38142\/"},"modified":"2024-11-26T13:39:25","modified_gmt":"2024-11-26T05:39:25","slug":"java%e9%87%8c%e9%9d%a2%e6%95%b4%e6%95%b0%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38142\/","title":{"rendered":"JAVA\u91cc\u9762\u6574\u6570\u6570\u7ec4\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u4f7f\u7528\u65b9\u62ec\u53f7\u58f0\u660e\u6574\u6570\u6570\u7ec4\uff0c\u5e76\u4ee5\u5927\u62ec\u53f7\u6216 new \u5173\u952e\u5b57\u8fdb\u884c\u521d\u59cb\u5316\u3002\u4f7f\u7528\u65b9\u62ec\u53f7\u53ef\u4ee5\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u7ec4\u5143\u7d20\uff0c\u4f46\u957f\u5ea6\u4e0d\u53ef\u66f4\u6539\uff0c\u5143\u7d20\u6309\u503c\u4f20\u9012\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/14\/2024111409280129722.jpg\" class=\"aligncenter\" title=\"JAVA\u91cc\u9762\u6574\u6570\u6570\u7ec4\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"JAVA\u91cc\u9762\u6574\u6570\u6570\u7ec4\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 JAVA \u4e2d\u58f0\u660e\u548c\u521d\u59cb\u5316\u6574\u6570\u6570\u7ec4<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u58f0\u660e\u548c\u521d\u59cb\u5316\u6574\u6570\u6570\u7ec4\u975e\u5e38\u7b80\u5355\u3002<\/p>\n<p><strong>\u58f0\u660e\u4e00\u4e2a\u6574\u6570\u6570\u7ec4<\/strong><\/p>\n<pre>int[] numbers;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u58f0\u660e\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u610f\u6570\u91cf\u6574\u6570\u503c\u7684\u6574\u6570\u6570\u7ec4\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u521d\u59cb\u5316\u4e00\u4e2a\u6574\u6570\u6570\u7ec4<\/strong><\/p>\n<p>\u6709\u4e24\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\u53ef\u4ee5\u521d\u59cb\u5316\u6574\u6570\u6570\u7ec4\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u5927\u62ec\u53f7 ({})<\/strong><\/li>\n<\/ul>\n<pre>int[] numbers = {1, 2, 3, 4, 5};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li><strong>\u4f7f\u7528 new \u5173\u952e\u5b57<\/strong><\/li>\n<\/ul>\n<pre>int[] numbers = new int[5];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5927\u5c0f\u4e3a 5 \u7684\u6574\u6570\u6570\u7ec4\uff0c\u5e76\u5c06\u5176\u521d\u59cb\u5316\u4e3a\u9ed8\u8ba4\u503c 0\u3002<\/p>\n<p><strong>\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u7ec4\u5143\u7d20<\/strong><\/p>\n<p>\u4e00\u65e6\u6570\u7ec4\u58f0\u660e\u5e76\u521d\u59cb\u5316\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7 ([]) \u8bbf\u95ee\u548c\u4fee\u6539\u5143\u7d20\u3002<\/p>\n<pre>int firstElement = numbers[0]; \/\/ \u83b7\u53d6\u7b2c\u4e00\u4e2a\u5143\u7d20\nnumbers[1] = 10; \/\/ \u8bbe\u7f6e\u7b2c\u4e8c\u4e2a\u5143\u7d20\u7684\u503c\u4e3a 10<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u6570\u7ec4\u957f\u5ea6\u5728\u521b\u5efa\u540e\u4e0d\u80fd\u88ab\u4fee\u6539\u3002<\/li>\n<li>\u5c1d\u8bd5\u8bbf\u95ee\u6570\u7ec4\u8d85\u51fa\u8303\u56f4\u7684\u5143\u7d20\u4f1a\u5bfc\u81f4 ArrayIndexOutOfBoundsException\u3002<\/li>\n<li>\u6570\u7ec4\u5143\u7d20\u662f\u6309\u503c\u4f20\u9012\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5bf9\u6570\u7ec4\u5143\u7d20\u7684\u4fee\u6539\u4e0d\u4f1a\u5f71\u54cd\u539f\u59cb\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fJAVA\u91cc\u9762\u6574\u6570\u6570\u7ec4\u600e\u4e48\u5199\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>\u5728 java \u4e2d\uff0c\u4f7f\u7528\u65b9\u62ec\u53f7\u58f0\u660e\u6574\u6570\u6570\u7ec4\uff0c\u5e76\u4ee5\u5927\u62ec\u53f7\u6216 new \u5173\u952e\u5b57\u8fdb\u884c\u521d\u59cb\u5316\u3002\u4f7f\u7528\u65b9\u62ec\u53f7\u53ef\u4ee5\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u7ec4\u5143\u7d20\uff0c\u4f46\u957f\u5ea6\u4e0d\u53ef\u66f4\u6539\uff0c\u5143\u7d20\u6309\u503c\u4f20\u9012\u3002 \u5982\u4f55\u5728 JAVA \u4e2d\u58f0\u660e\u548c\u521d\u59cb\u5316\u6574\u6570\u6570\u7ec4 \u5728 Java \u4e2d\uff0c\u58f0\u660e\u548c\u521d\u59cb\u5316\u6574\u6570\u6570\u7ec4\u975e\u5e38\u7b80\u5355\u3002 \u58f0\u660e\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 int[] numbers; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u58f0\u660e\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u610f\u6570\u91cf\u6574\u6570\u503c\u7684\u6574\u6570\u6570\u7ec4\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u521d\u59cb\u5316\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 \u6709\u4e24\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\u53ef\u4ee5\u521d\u59cb\u5316\u6574\u6570\u6570\u7ec4\uff1a \u4f7f\u7528\u5927\u62ec\u53f7 ({}) int[] numbers = {1, 2, 3, 4, 5}; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 new \u5173\u952e\u5b57 int[] numbers = new int[5]; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5927\u5c0f\u4e3a 5 \u7684\u6574\u6570\u6570\u7ec4\uff0c\u5e76\u5c06\u5176\u521d\u59cb\u5316\u4e3a\u9ed8\u8ba4\u503c 0\u3002 \u8bbf\u95ee\u548c\u4fee\u6539\u6570\u7ec4\u5143\u7d20 \u4e00\u65e6\u6570\u7ec4\u58f0\u660e\u5e76\u521d\u59cb\u5316\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7 ([]) \u8bbf\u95ee\u548c\u4fee\u6539\u5143\u7d20\u3002 int firstElement = numbers[0]; \/\/ \u83b7\u53d6\u7b2c\u4e00\u4e2a\u5143\u7d20 numbers[1] = [&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-38142","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38142","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=38142"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38142\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}