{"id":65519,"date":"2025-05-03T09:14:55","date_gmt":"2025-05-03T01:14:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65519\/"},"modified":"2025-05-03T09:14:55","modified_gmt":"2025-05-03T01:14:55","slug":"java-%e9%87%8c%e6%80%8e%e4%b9%88%e7%bb%99%e6%95%b0%e7%bb%84%e8%b5%8b%e5%80%bc-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65519\/","title":{"rendered":"java \u91cc\u600e\u4e48\u7ed9\u6570\u7ec4\u8d4b\u503c"},"content":{"rendered":"<blockquote><p>\n  java \u6570\u7ec4\u8d4b\u503c\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u76f4\u63a5\u8d4b\u503c\uff1a\u9010\u4e2a\u8d4b\u503c\u3002\u6570\u7ec4\u521d\u59cb\u5316\u5668\uff1a\u4e00\u6b21\u6027\u8d4b\u503c\u3002\u5faa\u73af\uff1a\u9002\u7528\u4e8e\u5927\u578b\u6570\u7ec4\u6216\u6d89\u53ca\u8ba1\u7b97\u3002arrays.fill() \u65b9\u6cd5\uff1a\u4e3a\u6240\u6709\u5143\u7d20\u8d4b\u503c\u4e3a\u7279\u5b9a\u503c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111302484380788.jpg\" class=\"aligncenter\" title=\"java \u91cc\u600e\u4e48\u7ed9\u6570\u7ec4\u8d4b\u503c\u63d2\u56fe\" alt=\"java \u91cc\u600e\u4e48\u7ed9\u6570\u7ec4\u8d4b\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7ed9 Java \u4e2d\u7684\u6570\u7ec4\u8d4b\u503c<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u8d4b\u503c<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u76f4\u63a5\u7ed9\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8d4b\u503c\uff1a<\/p>\n<pre>int[] arr = new int[5];\narr[0] = 10;\narr[1] = 20;\narr[2] = 30;\n\/\/ \u4f9d\u6b64\u7c7b\u63a8<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668\uff0c\u4e00\u6b21\u6027\u4e3a\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u8d4b\u503c\uff1a<\/p>\n<pre>int[] arr = {10, 20, 30, 40, 50};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u5faa\u73af<\/strong><\/p>\n<p>\u5bf9\u4e8e\u5927\u578b\u6570\u7ec4\u6216\u6d89\u53ca\u8ba1\u7b97\u7684\u8d4b\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\uff1a<\/p>\n<pre>int[] arr = new int[100];\nfor (int i = 0; i &lt; arr.length; i++) {\n    arr[i] = i * 2;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Arrays.fill() \u65b9\u6cd5<\/strong><\/p>\n<p>Java \u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a Arrays.fill() \u65b9\u6cd5\uff0c\u53ef\u4ee5\u4e3a\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u8d4b\u503c\u4e3a\u4e00\u4e2a\u7279\u5b9a\u7684\u503c\uff1a<\/p>\n<pre>int[] arr = new int[50];\nArrays.fill(arr, 10);  \/\/ \u4e3a\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u8d4b\u503c\u4e3a 10<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u8d4b\u503c\u65f6\uff0c\u7d22\u5f15\u5fc5\u987b\u5728\u6570\u7ec4\u7684\u6709\u6548\u8303\u56f4\u5185\uff08\u4ece 0 \u5230\u6570\u7ec4\u957f\u5ea6 &#8211; 1\uff09\u3002<\/li>\n<li>\u4e3a\u539f\u59cb\u7c7b\u578b\u6570\u7ec4\uff08\u4f8b\u5982 int[]\uff09\u8d4b\u503c\u65f6\uff0c\u6570\u7ec4\u4e2d\u7684\u539f\u59cb\u503c\u5c06\u88ab\u8986\u76d6\u3002<\/li>\n<li>\u4e3a\u5bf9\u8c61\u6570\u7ec4\uff08\u4f8b\u5982 String[]\uff09\u8d4b\u503c\u65f6\uff0c\u6570\u7ec4\u4e2d\u7684\u5bf9\u8c61\u5f15\u7528\u5c06\u88ab\u66f4\u6539\uff0c\u4f46\u5bf9\u8c61\u672c\u8eab\u4e0d\u4f1a\u88ab\u4fee\u6539\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava \u91cc\u600e\u4e48\u7ed9\u6570\u7ec4\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>java \u6570\u7ec4\u8d4b\u503c\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u76f4\u63a5\u8d4b\u503c\uff1a\u9010\u4e2a\u8d4b\u503c\u3002\u6570\u7ec4\u521d\u59cb\u5316\u5668\uff1a\u4e00\u6b21\u6027\u8d4b\u503c\u3002\u5faa\u73af\uff1a\u9002\u7528\u4e8e\u5927\u578b\u6570\u7ec4\u6216\u6d89\u53ca\u8ba1\u7b97\u3002arrays.fill() \u65b9\u6cd5\uff1a\u4e3a\u6240\u6709\u5143\u7d20\u8d4b\u503c\u4e3a\u7279\u5b9a\u503c\u3002 \u5982\u4f55\u7ed9 Java \u4e2d\u7684\u6570\u7ec4\u8d4b\u503c \u76f4\u63a5\u8d4b\u503c \u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u76f4\u63a5\u7ed9\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8d4b\u503c\uff1a int[] arr = new int[5]; arr[0] = 10; arr[1] = 20; arr[2] = 30; \/\/ \u4f9d\u6b64\u7c7b\u63a8 \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668\uff0c\u4e00\u6b21\u6027\u4e3a\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u8d4b\u503c\uff1a int[] arr = {10, 20, 30, 40, 50}; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u5faa\u73af \u5bf9\u4e8e\u5927\u578b\u6570\u7ec4\u6216\u6d89\u53ca\u8ba1\u7b97\u7684\u8d4b\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\uff1a int[] arr = new int[100]; for (int i = 0; i &lt; arr.length; i++) { arr[i] [&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-65519","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65519","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=65519"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65519\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}