{"id":39612,"date":"2024-11-26T09:17:11","date_gmt":"2024-11-26T01:17:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39612\/"},"modified":"2024-11-26T09:17:11","modified_gmt":"2024-11-26T01:17:11","slug":"java%e6%80%8e%e4%b9%88%e4%bf%ae%e6%94%b9%e9%9b%86%e5%90%88%e4%b8%ad%e6%95%b0%e7%bb%84%e7%9a%84%e6%95%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39612\/","title":{"rendered":"Java\u600e\u4e48\u4fee\u6539\u96c6\u5408\u4e2d\u6570\u7ec4\u7684\u6570"},"content":{"rendered":"<blockquote><p>\n  \u4fee\u6539 java \u96c6\u5408\u4e2d\u6570\u7ec4\u5143\u7d20\u7684\u65b9\u6cd5\u6709\u4e09\u79cd\uff1a\u76f4\u63a5\u8bbf\u95ee\u7d22\u5f15\u3001\u4f7f\u7528\u8fed\u4ee3\u5668\u3001\u514b\u9686\u5e76\u4fee\u6539\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111618433344970.jpg\" class=\"aligncenter\" title=\"Java\u600e\u4e48\u4fee\u6539\u96c6\u5408\u4e2d\u6570\u7ec4\u7684\u6570\u63d2\u56fe\" alt=\"Java\u600e\u4e48\u4fee\u6539\u96c6\u5408\u4e2d\u6570\u7ec4\u7684\u6570\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4fee\u6539 Java \u96c6\u5408\u4e2d\u6570\u7ec4\u7684\u5143\u7d20<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u8bbf\u95ee\u7d22\u5f15<\/strong><\/p>\n<p>\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u76f4\u63a5\u8bbf\u95ee\u6570\u7ec4\u7684\u7d22\u5f15\u3002\u5bf9\u4e8e\u6570\u7ec4\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528 set() \u65b9\u6cd5\uff0c\u5bf9\u4e8e\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 [ ] \u8bed\u6cd5\uff1a<\/p>\n<pre>List&lt;Integer&gt; list = new ArrayList&lt;&gt;();\nlist.add(1);\nlist.add(2);\nlist.set(0, 3); \/\/ \u4fee\u6539\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e3a 3\n\nint[] array = new int[2];\narray[0] = 1;\narray[1] = 2;\narray[0] = 3; \/\/ \u4fee\u6539\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e3a 3<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u8fed\u4ee3\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\u8fed\u4ee3\u5668\u3002\u8fed\u4ee3\u5668\u9010\u4e2a\u8bbf\u95ee\u96c6\u5408\u4e2d\u7684\u5143\u7d20\uff0c\u5141\u8bb8\u4fee\u6539\u6bcf\u4e2a\u5143\u7d20\uff1a<\/p>\n<pre>List&lt;Integer&gt; list = new ArrayList&lt;&gt;();\nlist.add(1);\nlist.add(2);\n\nIterator&lt;Integer&gt; it = list.iterator();\nwhile (it.hasNext()) {\n    int element = it.next();\n    if (element == 1) {\n        it.remove(); \/\/ \u5220\u9664\u5143\u7d20 1\n        it.add(3); \/\/ \u6dfb\u52a0\u5143\u7d20 3\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u514b\u9686\u5e76\u4fee\u6539<\/strong><\/p>\n<p>\u5982\u679c\u5e0c\u671b\u4fee\u6539\u6570\u7ec4\u800c\u4e0d\u5f71\u54cd\u539f\u59cb\u96c6\u5408\uff0c\u53ef\u4ee5\u4f7f\u7528\u514b\u9686\u64cd\u4f5c\u3002\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u539f\u59cb\u6570\u7ec4\u7684\u526f\u672c\uff0c\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u4fee\u6539\u800c\u4e0d\u4fee\u6539\u539f\u59cb\u6570\u7ec4\uff1a<\/p>\n<pre>List&lt;Integer&gt; list = new ArrayList&lt;&gt;();\nlist.add(1);\nlist.add(2);\n\nList&lt;Integer&gt; modifiedList = new ArrayList&lt;&gt;(list); \/\/ \u514b\u9686\u5217\u8868\nmodifiedList.set(0, 3); \/\/ \u4fee\u6539\u514b\u9686\u5217\u8868\n\nSystem.out.println(list); \/\/ [1, 2]\nSystem.out.println(modifiedList); \/\/ [3, 2]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava\u600e\u4e48\u4fee\u6539\u96c6\u5408\u4e2d\u6570\u7ec4\u7684\u6570\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>\u4fee\u6539 java \u96c6\u5408\u4e2d\u6570\u7ec4\u5143\u7d20\u7684\u65b9\u6cd5\u6709\u4e09\u79cd\uff1a\u76f4\u63a5\u8bbf\u95ee\u7d22\u5f15\u3001\u4f7f\u7528\u8fed\u4ee3\u5668\u3001\u514b\u9686\u5e76\u4fee\u6539\u3002 \u5982\u4f55\u4fee\u6539 Java \u96c6\u5408\u4e2d\u6570\u7ec4\u7684\u5143\u7d20 \u76f4\u63a5\u8bbf\u95ee\u7d22\u5f15 \u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u76f4\u63a5\u8bbf\u95ee\u6570\u7ec4\u7684\u7d22\u5f15\u3002\u5bf9\u4e8e\u6570\u7ec4\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528 set() \u65b9\u6cd5\uff0c\u5bf9\u4e8e\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 [ ] \u8bed\u6cd5\uff1a List&lt;Integer&gt; list = new ArrayList&lt;&gt;(); list.add(1); list.add(2); list.set(0, 3); \/\/ \u4fee\u6539\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e3a 3 int[] array = new int[2]; array[0] = 1; array[1] = 2; array[0] = 3; \/\/ \u4fee\u6539\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e3a 3 \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u8fed\u4ee3\u5668 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u8fed\u4ee3\u5668\u3002\u8fed\u4ee3\u5668\u9010\u4e2a\u8bbf\u95ee\u96c6\u5408\u4e2d\u7684\u5143\u7d20\uff0c\u5141\u8bb8\u4fee\u6539\u6bcf\u4e2a\u5143\u7d20\uff1a List&lt;Integer&gt; list = new ArrayList&lt;&gt;(); list.add(1); list.add(2); Iterator&lt;Integer&gt; it [&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-39612","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39612","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=39612"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39612\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}