{"id":65882,"date":"2025-05-03T15:14:13","date_gmt":"2025-05-03T07:14:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65882\/"},"modified":"2025-05-03T15:14:13","modified_gmt":"2025-05-03T07:14:13","slug":"java%e6%80%8e%e4%b9%88%e7%bb%99%e6%95%b0%e7%bb%84%e5%85%a8%e9%83%a8%e8%b5%8b%e5%80%bc0-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65882\/","title":{"rendered":"java\u600e\u4e48\u7ed9\u6570\u7ec4\u5168\u90e8\u8d4b\u503c0"},"content":{"rendered":"<blockquote><p>\n  \u53ef\u4ee5\u7528\u4ee5\u4e0b\u65b9\u6cd5\u7ed9 java \u6570\u7ec4\u5168\u90e8\u8d4b\u503c\u4e3a 0\uff1a1. \u4f7f\u7528\u586b\u5145\u65b9\u6cd5\uff1aarrays.fill()\uff1b2. \u4f7f\u7528 for \u5faa\u73af\uff1b3. \u4f7f\u7528\u6d41 api\uff1aintstream.generate()\uff1b4. \u521b\u5efa\u4e00\u4e2a\u5305\u542b 0 \u7684\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111313573968080.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u7ed9\u6570\u7ec4\u5168\u90e8\u8d4b\u503c0\u63d2\u56fe\" alt=\"java\u600e\u4e48\u7ed9\u6570\u7ec4\u5168\u90e8\u8d4b\u503c0\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7528 Java \u7ed9\u6570\u7ec4\u5168\u90e8\u8d4b\u503c\u4e3a 0<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u7ed9\u6570\u7ec4\u5168\u90e8\u8d4b\u503c\u4e3a 0\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u586b\u5145\u65b9\u6cd5<\/strong><\/p>\n<pre>public static void main(String[] args) {\n    int[] arr = new int[10];\n    Arrays.fill(arr, 0);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 for \u5faa\u73af<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>public static void main(String[] args) {\n    int[] arr = new int[10];\n\n    for (int i = 0; i &lt; arr.length; i++) {\n        arr[i] = 0;\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528\u6d41 API<\/strong><\/p>\n<pre>public static void main(String[] args) {\n    int[] arr = IntStream.generate(() -&gt; 0).limit(10).toArray();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u521b\u5efa\u4e00\u4e2a\u5305\u542b 0 \u7684\u6570\u7ec4<\/strong><\/p>\n<pre>public static void main(String[] args) {\n    int[] arr = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u7ed9\u6570\u7ec4\u5168\u90e8\u8d4b\u503c0\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>\u53ef\u4ee5\u7528\u4ee5\u4e0b\u65b9\u6cd5\u7ed9 java \u6570\u7ec4\u5168\u90e8\u8d4b\u503c\u4e3a 0\uff1a1. \u4f7f\u7528\u586b\u5145\u65b9\u6cd5\uff1aarrays.fill()\uff1b2. \u4f7f\u7528 for \u5faa\u73af\uff1b3. \u4f7f\u7528\u6d41 api\uff1aintstream.generate()\uff1b4. \u521b\u5efa\u4e00\u4e2a\u5305\u542b 0 \u7684\u6570\u7ec4\u3002 \u5982\u4f55\u7528 Java \u7ed9\u6570\u7ec4\u5168\u90e8\u8d4b\u503c\u4e3a 0 \u5728 Java \u4e2d\uff0c\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u7ed9\u6570\u7ec4\u5168\u90e8\u8d4b\u503c\u4e3a 0\uff1a 1. \u4f7f\u7528\u586b\u5145\u65b9\u6cd5 public static void main(String[] args) { int[] arr = new int[10]; Arrays.fill(arr, 0); } \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 for \u5faa\u73af \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b public static void main(String[] args) { int[] arr = new int[10]; for [&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-65882","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65882","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=65882"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65882\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}