{"id":39449,"date":"2024-11-26T08:30:19","date_gmt":"2024-11-26T00:30:19","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39449\/"},"modified":"2024-11-26T08:30:19","modified_gmt":"2024-11-26T00:30:19","slug":"java%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%85%a8%e9%83%a8%e5%88%9d%e5%a7%8b%e5%8c%96%e4%b8%ba0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39449\/","title":{"rendered":"java\u6570\u7ec4\u600e\u4e48\u5168\u90e8\u521d\u59cb\u5316\u4e3a0"},"content":{"rendered":"<blockquote><p>\n  java \u6570\u7ec4\u521d\u59cb\u5316\u4e3a 0 \u7684\u4e24\u79cd\u65b9\u6cd5\uff1a1. \u4f7f\u7528\u5faa\u73af\u548c\u6570\u7ec4\u8d4b\u503c\uff1b2. \u4f7f\u7528 arrays.fill() \u65b9\u6cd5\u3002arrays.fill() \u65b9\u6cd5\u6548\u7387\u66f4\u9ad8\uff0c\u56e0\u4e3a\u5b83\u4f7f\u7528\u5e95\u5c42\u7cfb\u7edf\u8c03\u7528\u586b\u5145\u6570\u7ec4\uff0c\u800c\u5faa\u73af\u65b9\u6cd5\u9700\u8981\u9010\u4e2a\u5143\u7d20\u5730\u8fdb\u884c\u8d4b\u503c\u3002\u8be5\u65b9\u6cd5\u4ec5\u9002\u7528\u4e8e\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6570\u7ec4\uff0c\u5f15\u7528\u7c7b\u578b\u6570\u7ec4\u9700\u8981\u624b\u52a8\u5c06\u6bcf\u4e2a\u5143\u7d20\u8bbe\u7f6e\u4e3a null\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111610545773647.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u600e\u4e48\u5168\u90e8\u521d\u59cb\u5316\u4e3a0\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u600e\u4e48\u5168\u90e8\u521d\u59cb\u5316\u4e3a0\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 Java \u6570\u7ec4\u5168\u90e8\u521d\u59cb\u5316\u4e3a 0<\/strong><\/p>\n<p>Java \u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u5168\u90e8\u521d\u59cb\u5316\u4e3a 0\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u5faa\u73af\u548c\u6570\u7ec4\u8d4b\u503c<\/strong><\/p>\n<pre>int[] myArray = new int[10];\nfor (int i = 0; i &lt; myArray.length; i++) {\n    myArray[i] = 0;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 Arrays.fill() \u65b9\u6cd5<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] myArray = new int[10];\nArrays.fill(myArray, 0);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u54ea\u79cd\u65b9\u6cd5\u66f4\u597d\uff1f<\/strong><\/p>\n<p>\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u5b9e\u73b0\u5c06\u6570\u7ec4\u5168\u90e8\u521d\u59cb\u5316\u4e3a 0 \u7684\u76ee\u7684\uff0c\u4f46\u901a\u5e38 Arrays.fill() \u65b9\u6cd5\u6548\u7387\u66f4\u9ad8\u3002\u8fd9\u662f\u56e0\u4e3a\u8be5\u65b9\u6cd5\u4f7f\u7528\u5e95\u5c42\u7cfb\u7edf\u8c03\u7528\u6765\u586b\u5145\u6570\u7ec4\uff0c\u800c\u5faa\u73af\u65b9\u6cd5\u9700\u8981\u9010\u4e2a\u5143\u7d20\u5730\u8fdb\u884c\u8d4b\u503c\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u8fd9\u4e9b\u65b9\u6cd5\u4ec5\u9002\u7528\u4e8e\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6570\u7ec4\uff0c\u4f8b\u5982 int[]\u3002\u5b83\u4eec\u4e0d\u9002\u7528\u4e8e\u5f15\u7528\u7c7b\u578b\u6570\u7ec4\uff0c\u4f8b\u5982 Object[]\u3002<\/li>\n<li>\u5bf9\u4e8e\u5f15\u7528\u7c7b\u578b\u6570\u7ec4\uff0c\u9700\u8981\u624b\u52a8\u5c06\u6bcf\u4e2a\u5143\u7d20\u8bbe\u7f6e\u4e3a null\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>int[] numbers = new int[5];\nArrays.fill(numbers, 0);\nSystem.out.println(Arrays.toString(numbers)); \/\/ \u8f93\u51fa\uff1a[0, 0, 0, 0, 0]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u600e\u4e48\u5168\u90e8\u521d\u59cb\u5316\u4e3a0\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 \u6570\u7ec4\u521d\u59cb\u5316\u4e3a 0 \u7684\u4e24\u79cd\u65b9\u6cd5\uff1a1. \u4f7f\u7528\u5faa\u73af\u548c\u6570\u7ec4\u8d4b\u503c\uff1b2. \u4f7f\u7528 arrays.fill() \u65b9\u6cd5\u3002arrays.fill() \u65b9\u6cd5\u6548\u7387\u66f4\u9ad8\uff0c\u56e0\u4e3a\u5b83\u4f7f\u7528\u5e95\u5c42\u7cfb\u7edf\u8c03\u7528\u586b\u5145\u6570\u7ec4\uff0c\u800c\u5faa\u73af\u65b9\u6cd5\u9700\u8981\u9010\u4e2a\u5143\u7d20\u5730\u8fdb\u884c\u8d4b\u503c\u3002\u8be5\u65b9\u6cd5\u4ec5\u9002\u7528\u4e8e\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6570\u7ec4\uff0c\u5f15\u7528\u7c7b\u578b\u6570\u7ec4\u9700\u8981\u624b\u52a8\u5c06\u6bcf\u4e2a\u5143\u7d20\u8bbe\u7f6e\u4e3a null\u3002 \u5982\u4f55\u5c06 Java \u6570\u7ec4\u5168\u90e8\u521d\u59cb\u5316\u4e3a 0 Java \u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u5168\u90e8\u521d\u59cb\u5316\u4e3a 0\uff1a 1. \u4f7f\u7528\u5faa\u73af\u548c\u6570\u7ec4\u8d4b\u503c int[] myArray = new int[10]; for (int i = 0; i &lt; myArray.length; i++) { myArray[i] = 0; } \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 Arrays.fill() \u65b9\u6cd5 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] myArray = new int[10]; Arrays.fill(myArray, 0); \u767b\u5f55\u540e\u590d\u5236 \u54ea\u79cd\u65b9\u6cd5\u66f4\u597d\uff1f \u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u5b9e\u73b0\u5c06\u6570\u7ec4\u5168\u90e8\u521d\u59cb\u5316\u4e3a 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-39449","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39449","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=39449"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39449\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}