{"id":66008,"date":"2025-05-03T13:14:41","date_gmt":"2025-05-03T05:14:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66008\/"},"modified":"2025-05-03T13:14:41","modified_gmt":"2025-05-03T05:14:41","slug":"java%e6%80%8e%e4%b9%88%e7%bb%99%e6%95%b0%e7%bb%84%e6%95%b4%e4%bd%93%e8%b5%8b%e5%80%bc1-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66008\/","title":{"rendered":"java\u600e\u4e48\u7ed9\u6570\u7ec4\u6574\u4f53\u8d4b\u503c1"},"content":{"rendered":"<blockquote><p>\n  \u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u7ed9 java \u6570\u7ec4\u6574\u4f53\u8d4b\u503c\uff1a\u4f7f\u7528\u5faa\u73af\u904d\u5386\u6570\u7ec4\u5143\u7d20\u5e76\u9010\u4e2a\u8d4b\u503c\uff1b\u4f7f\u7528 arrays.fill() \u65b9\u6cd5\u5c06\u6240\u6709\u5143\u7d20\u8d4b\u503c\u4e3a\u6307\u5b9a\u7684\u503c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/14\/2024111410511680369.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u7ed9\u6570\u7ec4\u6574\u4f53\u8d4b\u503c1\u63d2\u56fe\" alt=\"java\u600e\u4e48\u7ed9\u6570\u7ec4\u6574\u4f53\u8d4b\u503c1\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7ed9 Java \u6570\u7ec4\u6574\u4f53\u8d4b\u503c\uff1f<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u7ed9\u6570\u7ec4\u6574\u4f53\u8d4b\u503c\uff1a<\/p>\n<ol>\n<li><strong>\u58f0\u660e\u5e76\u521d\u59cb\u5316\u6570\u7ec4\u53d8\u91cf\uff1a<\/strong><\/li>\n<\/ol>\n<pre>int[] numbers = new int[5]; \/\/ \u58f0\u660e\u4e00\u4e2a\u957f\u5ea6\u4e3a 5 \u7684\u6574\u6570\u6570\u7ec4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u904d\u5386\u6570\u7ec4\u5143\u7d20\uff1a<\/strong><\/li>\n<\/ol>\n<pre>for (int i = 0; i &lt; numbers.length; i++) {\n    numbers[i] = 10; \/\/ \u5c06\u6bcf\u4e2a\u5143\u7d20\u8d4b\u503c\u4e3a 10\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>i \u662f\u5faa\u73af\u53d8\u91cf\uff0c\u4ee3\u8868\u6570\u7ec4\u5143\u7d20\u7684\u7d22\u5f15<\/li>\n<li>numbers.length \u662f\u6570\u7ec4\u7684\u957f\u5ea6<\/li>\n<\/ul>\n<ol>\n<li><strong>\u4f7f\u7528 Arrays.fill() \u65b9\u6cd5\uff1a<\/strong><\/li>\n<\/ol>\n<p>Arrays.fill() \u65b9\u6cd5\u53ef\u4ee5\u5c06\u6570\u7ec4\u7684\u6240\u6709\u5143\u7d20\u8d4b\u503c\u4e3a\u6307\u5b9a\u7684\u503c\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>Arrays.fill(numbers, 10);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u628a numbers \u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u8d4b\u503c\u4e3a 10\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u7ed9\u6570\u7ec4\u6574\u4f53\u8d4b\u503c\u4e3a 10\uff1a<\/p>\n<pre>public class ArrayAssignment {\n\n    public static void main(String[] args) {\n        int[] numbers = new int[5];\n\n        \/\/ \u4f7f\u7528\u5faa\u73af\u8d4b\u503c\n        for (int i = 0; i &lt; numbers.length; i++) {\n            numbers[i] = 10;\n        }\n\n        \/\/ \u4f7f\u7528 Arrays.fill() \u8d4b\u503c\n        int[] otherNumbers = new int[5];\n        Arrays.fill(otherNumbers, 10);\n\n        \/\/ \u6253\u5370\u6570\u7ec4\u5185\u5bb9\n        for (int num : numbers) {\n            System.out.print(num + \" \");\n        }\n        System.out.println();\n        for (int num : otherNumbers) {\n            System.out.print(num + \" \");\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>10 10 10 10 10\n10 10 10 10 10<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u7ed9\u6570\u7ec4\u6574\u4f53\u8d4b\u503c1\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>\u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u7ed9 java \u6570\u7ec4\u6574\u4f53\u8d4b\u503c\uff1a\u4f7f\u7528\u5faa\u73af\u904d\u5386\u6570\u7ec4\u5143\u7d20\u5e76\u9010\u4e2a\u8d4b\u503c\uff1b\u4f7f\u7528 arrays.fill() \u65b9\u6cd5\u5c06\u6240\u6709\u5143\u7d20\u8d4b\u503c\u4e3a\u6307\u5b9a\u7684\u503c\u3002 \u5982\u4f55\u7ed9 Java \u6570\u7ec4\u6574\u4f53\u8d4b\u503c\uff1f \u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u7ed9\u6570\u7ec4\u6574\u4f53\u8d4b\u503c\uff1a \u58f0\u660e\u5e76\u521d\u59cb\u5316\u6570\u7ec4\u53d8\u91cf\uff1a int[] numbers = new int[5]; \/\/ \u58f0\u660e\u4e00\u4e2a\u957f\u5ea6\u4e3a 5 \u7684\u6574\u6570\u6570\u7ec4 \u767b\u5f55\u540e\u590d\u5236 \u904d\u5386\u6570\u7ec4\u5143\u7d20\uff1a for (int i = 0; i &lt; numbers.length; i++) { numbers[i] = 10; \/\/ \u5c06\u6bcf\u4e2a\u5143\u7d20\u8d4b\u503c\u4e3a 10 } \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a i \u662f\u5faa\u73af\u53d8\u91cf\uff0c\u4ee3\u8868\u6570\u7ec4\u5143\u7d20\u7684\u7d22\u5f15 numbers.length \u662f\u6570\u7ec4\u7684\u957f\u5ea6 \u4f7f\u7528 Arrays.fill() \u65b9\u6cd5\uff1a Arrays.fill() \u65b9\u6cd5\u53ef\u4ee5\u5c06\u6570\u7ec4\u7684\u6240\u6709\u5143\u7d20\u8d4b\u503c\u4e3a\u6307\u5b9a\u7684\u503c\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b Arrays.fill(numbers, 10); \u767b\u5f55\u540e\u590d\u5236 [&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-66008","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66008","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=66008"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66008\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}