{"id":64257,"date":"2025-05-03T11:02:24","date_gmt":"2025-05-03T03:02:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64257\/"},"modified":"2025-05-03T11:02:24","modified_gmt":"2025-05-03T03:02:24","slug":"java%e4%b8%ad%e6%80%8e%e4%b9%88%e8%bf%94%e5%9b%9e%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64257\/","title":{"rendered":"java\u4e2d\u600e\u4e48\u8fd4\u56de\u5b57\u7b26\u4e32\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u8fd4\u56de\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u65b9\u6cd5\u6709\uff1a\u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u5e76\u8fd4\u56de\u4f7f\u7528 string.split() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u6570\u7ec4\u4f7f\u7528 arrays.aslist() \u65b9\u6cd5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u518d\u8f6c\u6362\u4e3a\u6570\u7ec4\u4f7f\u7528 collectors.tolist() \u65b9\u6cd5\u5c06\u6d41\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u518d\u8f6c\u6362\u4e3a\u6570\u7ec4\u4f7f\u7528 joiner \u7c7b\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u518d\u8f6c\u6362\u4e3a\u6570\u7ec4\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/03\/2024110302100995756.jpg\" class=\"aligncenter\" title=\"java\u4e2d\u600e\u4e48\u8fd4\u56de\u5b57\u7b26\u4e32\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u4e2d\u600e\u4e48\u8fd4\u56de\u5b57\u7b26\u4e32\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u8fd4\u56de<\/strong><\/p>\n<p>Java \u4e2d\u8fd4\u56de\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u4ee5\u4e0b\u5217\u51fa\u4e86\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u5e76\u8fd4\u56de\u5b83<\/strong><\/p>\n<pre>public static String[] getStringArray() {\n    String[] strArr = {\"a\", \"b\", \"c\"};\n    return strArr;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 String.split() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u6570\u7ec4<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>public static String[] splitString(String str) {\n    String[] strArr = str.split(\",\");\n    return strArr;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u518d\u8f6c\u6362\u4e3a\u6570\u7ec4<\/strong><\/p>\n<pre>public static String[] convertToListAndBack(String[] strArr) {\n    List&lt;String&gt; strList = Arrays.asList(strArr);\n    String[] newArr = strList.toArray(new String[strList.size()]);\n    return newArr;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u4f7f\u7528 Collectors.toList() \u65b9\u6cd5\u5c06\u6d41\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u518d\u8f6c\u6362\u4e3a\u6570\u7ec4<\/strong><\/p>\n<pre>public static String[] convertStreamToListAndBack(String[] strArr) {\n    List&lt;String&gt; strList = Arrays.stream(strArr).collect(Collectors.toList());\n    String[] newArr = strList.toArray(new String[strList.size()]);\n    return newArr;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u4f7f\u7528 Joiner \u7c7b\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u518d\u8f6c\u6362\u4e3a\u6570\u7ec4<\/strong><\/p>\n<pre>public static String[] convertListToStringAndBack(List&lt;String&gt; strList) {\n    String str = Joiner.on(\",\").join(strList);\n    String[] strArr = str.split(\",\");\n    return strArr;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e2d\u600e\u4e48\u8fd4\u56de\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\u8fd4\u56de\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u65b9\u6cd5\u6709\uff1a\u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u5e76\u8fd4\u56de\u4f7f\u7528 string.split() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u6570\u7ec4\u4f7f\u7528 arrays.aslist() \u65b9\u6cd5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u518d\u8f6c\u6362\u4e3a\u6570\u7ec4\u4f7f\u7528 collectors.tolist() \u65b9\u6cd5\u5c06\u6d41\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u518d\u8f6c\u6362\u4e3a\u6570\u7ec4\u4f7f\u7528 joiner \u7c7b\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u518d\u8f6c\u6362\u4e3a\u6570\u7ec4 Java \u4e2d\u8fd4\u56de Java \u4e2d\u8fd4\u56de\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u4ee5\u4e0b\u5217\u51fa\u4e86\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff1a 1. \u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u5e76\u8fd4\u56de\u5b83 public static String[] getStringArray() { String[] strArr = {&#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;}; return strArr; } \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 String.split() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u6570\u7ec4 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b public static String[] splitString(String str) { String[] strArr = str.split(&#8220;,&#8221;); return strArr; } \u767b\u5f55\u540e\u590d\u5236 3. \u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u518d\u8f6c\u6362\u4e3a\u6570\u7ec4 public [&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-64257","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64257","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=64257"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64257\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}