{"id":65765,"date":"2025-05-03T11:18:14","date_gmt":"2025-05-03T03:18:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65765\/"},"modified":"2025-05-03T11:18:14","modified_gmt":"2025-05-03T03:18:14","slug":"java%e6%80%8e%e4%b9%88%e6%8a%8a%e6%95%b0%e7%bb%84%e8%bd%ac%e4%b8%balist-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65765\/","title":{"rendered":"java\u600e\u4e48\u628a\u6570\u7ec4\u8f6c\u4e3alist"},"content":{"rendered":"<blockquote><p>\n  \u5c06 java \u6570\u7ec4\u8f6c\u6362\u4e3a list \u7684\u65b9\u6cd5\u6709\uff1a\u76f4\u63a5\u8f6c\u6362\uff1aarrays.aslist() \u8fd4\u56de\u4e0d\u53ef\u53d8 list\u4f7f\u7528 list.of() \u65b9\u6cd5\uff1ajava 9 \u53ca\u4ee5\u4e0a\uff0c\u8fd4\u56de\u4e0d\u53ef\u53d8 list\u521b\u5efa\u53ef\u53d8 list\uff1aarraylist \u6784\u9020\u51fd\u6570\uff0c\u53ef\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111309304310087.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u628a\u6570\u7ec4\u8f6c\u4e3alist\u63d2\u56fe\" alt=\"java\u600e\u4e48\u628a\u6570\u7ec4\u8f6c\u4e3alist\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 Java \u6570\u7ec4\u8f6c\u6362\u4e3a List<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u8f6c\u6362\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\u3002\u6b64\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u57fa\u4e8e\u6307\u5b9a\u6570\u7ec4\u7684<strong>\u4e0d\u53ef\u53d8<\/strong> List\u3002<\/p>\n<pre>int[] numbers = {1, 2, 3, 4, 5};\nList&lt;Integer&gt; numbersList = Arrays.asList(numbers);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 List.of() \u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>Java 9 \u53ca\u66f4\u9ad8\u7248\u672c\u5f15\u5165\u4e86 List.of() \u5de5\u5382\u65b9\u6cd5\uff0c\u5b83\u521b\u5efa\u4e86\u4e00\u4e2a<strong>\u4e0d\u53ef\u53d8<\/strong> List\u3002<\/p>\n<pre>List&lt;Integer&gt; numbersList = List.of(1, 2, 3, 4, 5);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u521b\u5efa\u53ef\u53d8 List\uff1a<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u4e00\u4e2a<strong>\u53ef\u53d8<\/strong> List\uff0c\u8bf7\u4f7f\u7528 ArrayList \u6784\u9020\u51fd\u6570\u3002<\/p>\n<pre>int[] numbers = {1, 2, 3, 4, 5};\nList&lt;Integer&gt; numbersList = new ArrayList&lt;&gt;();\nfor (int number : numbers) {\n    numbersList.add(number);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>Arrays.asList() \u8fd4\u56de\u7684 List \u4e0d\u53ef\u53d8\uff0c\u8fd9\u610f\u5473\u7740\u60a8\u4e0d\u80fd\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\u3002<\/li>\n<li>List.of() \u65b9\u6cd5\u521b\u5efa\u7684 List \u4e5f\u662f\u4e0d\u53ef\u53d8\u7684\u3002<\/li>\n<li>ArrayList \u6784\u9020\u51fd\u6570\u521b\u5efa\u7684\u53ef\u53d8 List\uff0c\u53ef\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u628a\u6570\u7ec4\u8f6c\u4e3alist\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>\u5c06 java \u6570\u7ec4\u8f6c\u6362\u4e3a list \u7684\u65b9\u6cd5\u6709\uff1a\u76f4\u63a5\u8f6c\u6362\uff1aarrays.aslist() \u8fd4\u56de\u4e0d\u53ef\u53d8 list\u4f7f\u7528 list.of() \u65b9\u6cd5\uff1ajava 9 \u53ca\u4ee5\u4e0a\uff0c\u8fd4\u56de\u4e0d\u53ef\u53d8 list\u521b\u5efa\u53ef\u53d8 list\uff1aarraylist \u6784\u9020\u51fd\u6570\uff0c\u53ef\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20 \u5982\u4f55\u5c06 Java \u6570\u7ec4\u8f6c\u6362\u4e3a List \u76f4\u63a5\u8f6c\u6362\u65b9\u6cd5\uff1a \u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\u3002\u6b64\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u57fa\u4e8e\u6307\u5b9a\u6570\u7ec4\u7684\u4e0d\u53ef\u53d8 List\u3002 int[] numbers = {1, 2, 3, 4, 5}; List&lt;Integer&gt; numbersList = Arrays.asList(numbers); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 List.of() \u65b9\u6cd5\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b Java 9 \u53ca\u66f4\u9ad8\u7248\u672c\u5f15\u5165\u4e86 List.of() \u5de5\u5382\u65b9\u6cd5\uff0c\u5b83\u521b\u5efa\u4e86\u4e00\u4e2a\u4e0d\u53ef\u53d8 List\u3002 List&lt;Integer&gt; numbersList = List.of(1, 2, 3, 4, 5); \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-65765","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65765","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=65765"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65765\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}