{"id":37068,"date":"2024-11-26T13:45:01","date_gmt":"2024-11-26T05:45:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/37068\/"},"modified":"2024-11-26T13:45:01","modified_gmt":"2024-11-26T05:45:01","slug":"java%e4%b8%ad%e6%80%8e%e4%b9%88%e6%95%b0%e7%bb%84%e8%b5%8b%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/37068\/","title":{"rendered":"java\u4e2d\u600e\u4e48\u6570\u7ec4\u8d4b\u503c"},"content":{"rendered":"<blockquote><p>\n  java\u6570\u7ec4\u8d4b\u503c\u65b9\u6cd5\u5305\u62ec\uff1a\u76f4\u63a5\u8d4b\u503c\u3001new\u5173\u952e\u5b57\u521b\u5efa\u65b0\u6570\u7ec4\u3001\u4f7f\u7528\u5faa\u73af\u3001arrays.fill()\u65b9\u6cd5\u3002\u8d4b\u503c\u64cd\u4f5c\u7b26\u53ef\u7528\u4e8e\u5c06\u6570\u7ec4\u503c\u8d4b\u503c\u7ed9\u5176\u4ed6\u6570\u7ec4\u6216\u53d8\u91cf\uff0c\u4f46\u6ce8\u610f\u76ee\u6807\u548c\u6e90\u6570\u7ec4\u6307\u5411\u540c\u4e00\u5185\u5b58\u4f4d\u7f6e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111300421986791.jpg\" class=\"aligncenter\" title=\"java\u4e2d\u600e\u4e48\u6570\u7ec4\u8d4b\u503c\u63d2\u56fe\" alt=\"java\u4e2d\u600e\u4e48\u6570\u7ec4\u8d4b\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u6570\u7ec4\u8d4b\u503c<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5411\u6570\u7ec4\u5206\u914d\u503c\u3002<\/p>\n<p><strong>\u76f4\u63a5\u8d4b\u503c<\/strong><\/p>\n<p>\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u5927\u62ec\u53f7 ({}) \u6307\u5b9a\u6570\u7ec4\u5143\u7d20\u7684\u503c\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] numbers = {1, 2, 3, 4, 5};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd8\u53ef\u4ee5\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u7136\u540e\u4e3a\u5176\u5143\u7d20\u8d4b\u503c\uff1a<\/p>\n<pre>int[] numbers = new int[5];\nnumbers[0] = 1;\nnumbers[1] = 2;\nnumbers[2] = 3;\nnumbers[3] = 4;\nnumbers[4] = 5;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u5faa\u73af<\/strong><\/p>\n<p>\u5bf9\u4e8e\u8f83\u5927\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6765\u66f4\u65b9\u4fbf\u5730\u4e3a\u6bcf\u4e2a\u5143\u7d20\u8d4b\u503c\uff1a<\/p>\n<pre>int[] numbers = new int[100];\n\nfor (int i = 0; i &lt; numbers.length; i++) {\n    numbers[i] = i + 1;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Arrays.fill() \u65b9\u6cd5<\/strong><\/p>\n<pre>import java.util.Arrays;\n\nint[] numbers = new int[100];\nArrays.fill(numbers, 42);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u65b9\u6cd5\u5c06\u6570\u7ec4\u7684\u6240\u6709\u5143\u7d20\u586b\u5145\u4e3a\u6307\u5b9a\u7684\u503c\u3002<\/p>\n<p><strong>\u8d4b\u503c\u64cd\u4f5c<\/strong><\/p>\n<p>\u8d4b\u503c\u64cd\u4f5c\u7b26 (=) \u53ef\u7528\u4e8e\u5c06\u6570\u7ec4\u4e2d\u7684\u503c\u8d4b\u503c\u7ed9\u5176\u4ed6\u6570\u7ec4\u6216\u53d8\u91cf\uff1a<\/p>\n<pre>int[] original = {1, 2, 3};\nint[] copy = original;\ncopy[2] = 5;\n\nSystem.out.println(original[2]); \/\/ \u8f93\u51fa 5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4f7f\u7528\u8d4b\u503c\u64cd\u4f5c\u7b26\u65f6\uff0c\u6e90\u6570\u7ec4\u548c\u76ee\u6807\u6570\u7ec4\u5b9e\u9645\u4e0a\u6307\u5411\u540c\u4e00\u4e2a\u5185\u5b58\u4f4d\u7f6e\u3002\u56e0\u6b64\uff0c\u5bf9\u76ee\u6807\u6570\u7ec4\u7684\u4efb\u4f55\u66f4\u6539\u4e5f\u4f1a\u53cd\u6620\u5728\u6e90\u6570\u7ec4\u4e2d\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e2d\u600e\u4e48\u6570\u7ec4\u8d4b\u503c\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\u8d4b\u503c\u65b9\u6cd5\u5305\u62ec\uff1a\u76f4\u63a5\u8d4b\u503c\u3001new\u5173\u952e\u5b57\u521b\u5efa\u65b0\u6570\u7ec4\u3001\u4f7f\u7528\u5faa\u73af\u3001arrays.fill()\u65b9\u6cd5\u3002\u8d4b\u503c\u64cd\u4f5c\u7b26\u53ef\u7528\u4e8e\u5c06\u6570\u7ec4\u503c\u8d4b\u503c\u7ed9\u5176\u4ed6\u6570\u7ec4\u6216\u53d8\u91cf\uff0c\u4f46\u6ce8\u610f\u76ee\u6807\u548c\u6e90\u6570\u7ec4\u6307\u5411\u540c\u4e00\u5185\u5b58\u4f4d\u7f6e\u3002 Java \u6570\u7ec4\u8d4b\u503c \u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5411\u6570\u7ec4\u5206\u914d\u503c\u3002 \u76f4\u63a5\u8d4b\u503c \u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u5927\u62ec\u53f7 ({}) \u6307\u5b9a\u6570\u7ec4\u5143\u7d20\u7684\u503c\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] numbers = {1, 2, 3, 4, 5}; \u767b\u5f55\u540e\u590d\u5236 \u8fd8\u53ef\u4ee5\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u7136\u540e\u4e3a\u5176\u5143\u7d20\u8d4b\u503c\uff1a int[] numbers = new int[5]; numbers[0] = 1; numbers[1] = 2; numbers[2] = 3; numbers[3] = 4; numbers[4] = 5; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u5faa\u73af \u5bf9\u4e8e\u8f83\u5927\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6765\u66f4\u65b9\u4fbf\u5730\u4e3a\u6bcf\u4e2a\u5143\u7d20\u8d4b\u503c\uff1a int[] numbers = new int[100]; for (int 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-37068","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37068","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=37068"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37068\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=37068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=37068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=37068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}