{"id":37415,"date":"2024-11-26T15:55:45","date_gmt":"2024-11-26T07:55:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/37415\/"},"modified":"2024-11-26T15:55:45","modified_gmt":"2024-11-26T07:55:45","slug":"java%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e8%bd%ac%e6%88%90list%e9%9b%86%e5%90%88","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/37415\/","title":{"rendered":"java\u6570\u7ec4\u600e\u4e48\u8f6c\u6210list\u96c6\u5408"},"content":{"rendered":"<blockquote><p>\n  java \u6570\u7ec4\u8f6c\u6362\u4e3a list \u96c6\u5408\u7684\u65b9\u6cd5\u5305\u62ec\uff1a1. \u4f7f\u7528 arrays.aslist() \u521b\u5efa\u4e0d\u53ef\u53d8 list\uff1b2. \u4f7f\u7528 list.of() \u521b\u5efa\u4e0d\u53ef\u53d8 list\uff0c\u4ec5\u9002\u7528\u4e8e java 9 \u53ca\u4ee5\u4e0a\u7248\u672c\uff1b3. \u4f7f\u7528\u81ea\u5efa\u5faa\u73af\u521b\u5efa\u53ef\u53d8 list\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111305243713912.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u600e\u4e48\u8f6c\u6210list\u96c6\u5408\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u600e\u4e48\u8f6c\u6210list\u96c6\u5408\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u6570\u7ec4\u8f6c\u6362\u4e3a List \u96c6\u5408<\/strong><\/p>\n<p><strong>\u65b9\u6cd5 1\uff1aArrays.asList()<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u8f6c\u6362\u4e3a\u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\uff1a<\/p>\n<pre>int[] array = {1, 2, 3, 4, 5};\nList&lt;Integer&gt; list = Arrays.asList(array);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6ce8\u610f\uff1a\u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\u521b\u5efa\u7684 List \u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u8fd9\u610f\u5473\u7740\u4e0d\u80fd\u4fee\u6539\u5b83\u7684\u5143\u7d20\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u65b9\u6cd5 2\uff1aList.of()<\/strong><\/p>\n<p>Java 9 \u5f15\u5165\u4e86 List.of() \u65b9\u6cd5\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u4e0d\u53ef\u53d8 List\uff1a<\/p>\n<pre>int[] array = {1, 2, 3, 4, 5};\nList&lt;Integer&gt; list = List.of(array);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 3\uff1a\u81ea\u5efa\u5faa\u73af<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u9700\u8981\u4e00\u4e2a\u53ef\u53d8\u7684 List\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u5faa\u73af\u6765\u624b\u52a8\u521b\u5efa\u5b83\uff1a<\/p>\n<pre>int[] array = {1, 2, 3, 4, 5};\nList&lt;Integer&gt; list = new ArrayList&lt;&gt;();\n\nfor (int element : array) {\n  list.add(element);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u573a\u666f<\/strong><\/p>\n<p>\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a List \u96c6\u5408\u7684\u5e38\u89c1\u573a\u666f\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u5f53\u9700\u8981\u4f7f\u7528 List \u63d0\u4f9b\u7684\u65b9\u6cd5\u65f6\uff0c\u4f8b\u5982 sort() \u6216 filter()\u3002<\/li>\n<li>\u5f53\u9700\u8981\u5c06\u6570\u7ec4\u4f20\u9012\u7ed9\u671f\u671b List \u53c2\u6570\u7684\u65b9\u6cd5\u65f6\u3002<\/li>\n<li>\u5f53\u9700\u8981\u4fee\u6539\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u65f6\uff0c\u5e76\u4e14\u65e0\u6cd5\u4fee\u6539\u539f\u59cb\u6570\u7ec4\u65f6\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u600e\u4e48\u8f6c\u6210list\u96c6\u5408\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\u8f6c\u6362\u4e3a list \u96c6\u5408\u7684\u65b9\u6cd5\u5305\u62ec\uff1a1. \u4f7f\u7528 arrays.aslist() \u521b\u5efa\u4e0d\u53ef\u53d8 list\uff1b2. \u4f7f\u7528 list.of() \u521b\u5efa\u4e0d\u53ef\u53d8 list\uff0c\u4ec5\u9002\u7528\u4e8e java 9 \u53ca\u4ee5\u4e0a\u7248\u672c\uff1b3. \u4f7f\u7528\u81ea\u5efa\u5faa\u73af\u521b\u5efa\u53ef\u53d8 list\u3002 Java \u6570\u7ec4\u8f6c\u6362\u4e3a List \u96c6\u5408 \u65b9\u6cd5 1\uff1aArrays.asList() \u6700\u7b80\u5355\u7684\u8f6c\u6362\u4e3a\u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\uff1a int[] array = {1, 2, 3, 4, 5}; List&lt;Integer&gt; list = Arrays.asList(array); \u767b\u5f55\u540e\u590d\u5236 \u6ce8\u610f\uff1a\u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\u521b\u5efa\u7684 List \u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u8fd9\u610f\u5473\u7740\u4e0d\u80fd\u4fee\u6539\u5b83\u7684\u5143\u7d20\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u65b9\u6cd5 2\uff1aList.of() Java 9 \u5f15\u5165\u4e86 List.of() \u65b9\u6cd5\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u4e0d\u53ef\u53d8 List\uff1a int[] array [&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-37415","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37415","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=37415"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37415\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=37415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=37415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=37415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}