{"id":65266,"date":"2025-05-03T12:09:02","date_gmt":"2025-05-03T04:09:02","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65266\/"},"modified":"2025-05-03T12:09:02","modified_gmt":"2025-05-03T04:09:02","slug":"java%e6%80%8e%e4%b9%88%e6%95%b0%e7%bb%84%e8%bd%ac%e6%8d%a2-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65266\/","title":{"rendered":"java\u600e\u4e48\u6570\u7ec4\u8f6c\u6362"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528 arrays.aslist() \u8f6c\u6362\u4e3a\u5217\u8868\u3002\u4f7f\u7528 hashset \u6784\u9020\u51fd\u6570\u8f6c\u6362\u4e3a\u65e0\u91cd\u590d\u5143\u7d20\u7684\u96c6\u5408\u3002\u4f7f\u7528 hashmap \u6784\u9020\u51fd\u6570\u8f6c\u6362\u4e3a\u6620\u5c04\u3002\u4f7f\u7528 string.join() \u65b9\u6cd5\u8fde\u63a5\u6210\u5b57\u7b26\u4e32\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111215511844120.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u6570\u7ec4\u8f6c\u6362\u63d2\u56fe\" alt=\"java\u600e\u4e48\u6570\u7ec4\u8f6c\u6362\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u5982\u4f55\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5176\u4ed6\u6570\u636e\u7ed3\u6784<\/strong><\/p>\n<p><strong>\u7b80\u4ecb\uff1a<\/strong><br \/>\u5728 Java \u4e2d\uff0c\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u662f\u4e00\u9879\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u6b64\u64cd\u4f5c\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u76ee\u6807\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<p><strong>\u8f6c\u6362\u4e3a\u5217\u8868 (List)\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e00\u4e2a\u4e0d\u53ef\u4fee\u6539\u7684\u5217\u8868\u3002<\/li>\n<li>\n<pre>int[] arr = {1, 2, 3};\nList&lt;Integer&gt; list = Arrays.asList(arr);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f6c\u6362\u4e3a Set\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<\/li>\n<li>\u4f7f\u7528 HashSet \u6784\u9020\u51fd\u6570\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e00\u4e2a\u65e0\u5e8f\u96c6\u5408\uff0c\u96c6\u5408\u4e2d\u5143\u7d20\u4e0d\u91cd\u590d\u3002<\/li>\n<li>\n<pre>int[] arr = {1, 2, 3, 2};\nSet&lt;Integer&gt; set = new HashSet&lt;&gt;(Arrays.asList(arr));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u8f6c\u6362\u4e3a Map\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 HashMap \u6784\u9020\u51fd\u6570\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e00\u4e2a\u6620\u5c04\uff0c\u5176\u4e2d\u6570\u7ec4\u5143\u7d20\u88ab\u89c6\u4e3a\u952e\u548c\u503c\u5bf9\u3002<\/li>\n<li>\n<pre>String[] keys = {\"a\", \"b\", \"c\"};\nString[] values = {\"1\", \"2\", \"3\"};\nMap&lt;String, String&gt; map = new HashMap&lt;&gt;(Arrays.asList(keys, values));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff1a<\/strong><\/p>\n<\/li>\n<li>\u4f7f\u7528 String.join() \u65b9\u6cd5\u5c06\u6570\u7ec4\u5143\u7d20\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5e76\u6307\u5b9a\u5206\u9694\u7b26\u3002<\/li>\n<li>\n<pre>String[] arr = {\"Hello\", \"World\"};\nString str = String.join(\" \", arr); \/\/ \u8f93\u51fa\uff1a\"Hello World\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>Arrays.asList() \u8fd4\u56de\u7684\u5217\u8868\u662f\u4e0d\u53ef\u4fee\u6539\u7684\uff0c\u8fd9\u610f\u5473\u7740\u65e0\u6cd5\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\u3002<\/li>\n<li>\u5c06\u57fa\u672c\u7c7b\u578b\u6570\u7ec4\u8f6c\u6362\u4e3a\u96c6\u5408\u65f6\uff0c\u9700\u8981\u8fdb\u884c\u81ea\u52a8\u88c5\u7bb1\u3002<\/li>\n<li>\u67d0\u4e9b\u64cd\u4f5c\uff08\u4f8b\u5982\u6392\u5e8f\uff09\u5728\u6570\u7ec4\u4e0a\u6bd4\u5728\u5217\u8868\u6216\u96c6\u5408\u4e0a\u66f4\u6709\u6548\u7387\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u6570\u7ec4\u8f6c\u6362\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 \u4e2d\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528 arrays.aslist() \u8f6c\u6362\u4e3a\u5217\u8868\u3002\u4f7f\u7528 hashset \u6784\u9020\u51fd\u6570\u8f6c\u6362\u4e3a\u65e0\u91cd\u590d\u5143\u7d20\u7684\u96c6\u5408\u3002\u4f7f\u7528 hashmap \u6784\u9020\u51fd\u6570\u8f6c\u6362\u4e3a\u6620\u5c04\u3002\u4f7f\u7528 string.join() \u65b9\u6cd5\u8fde\u63a5\u6210\u5b57\u7b26\u4e32\u3002 Java \u4e2d\u5982\u4f55\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5176\u4ed6\u6570\u636e\u7ed3\u6784 \u7b80\u4ecb\uff1a\u5728 Java \u4e2d\uff0c\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u662f\u4e00\u9879\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u6b64\u64cd\u4f5c\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u76ee\u6807\u6570\u636e\u7ed3\u6784\u3002 \u8f6c\u6362\u4e3a\u5217\u8868 (List)\uff1a \u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e00\u4e2a\u4e0d\u53ef\u4fee\u6539\u7684\u5217\u8868\u3002 int[] arr = {1, 2, 3}; List&lt;Integer&gt; list = Arrays.asList(arr); \u767b\u5f55\u540e\u590d\u5236 \u8f6c\u6362\u4e3a Set\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4f7f\u7528 HashSet \u6784\u9020\u51fd\u6570\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e00\u4e2a\u65e0\u5e8f\u96c6\u5408\uff0c\u96c6\u5408\u4e2d\u5143\u7d20\u4e0d\u91cd\u590d\u3002 int[] arr = {1, 2, 3, 2}; Set&lt;Integer&gt; set = new HashSet&lt;&gt;(Arrays.asList(arr)); \u767b\u5f55\u540e\u590d\u5236 \u8f6c\u6362\u4e3a Map\uff1a \u4f7f\u7528 HashMap \u6784\u9020\u51fd\u6570\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u4e00\u4e2a\u6620\u5c04\uff0c\u5176\u4e2d\u6570\u7ec4\u5143\u7d20\u88ab\u89c6\u4e3a\u952e\u548c\u503c\u5bf9\u3002 [&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-65266","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65266","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=65266"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65266\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}