{"id":1133,"date":"2026-03-28T23:07:55","date_gmt":"2026-03-28T15:07:55","guid":{"rendered":"https:\/\/yunyanglib.cn\/?p=1133"},"modified":"2026-03-28T23:07:56","modified_gmt":"2026-03-28T15:07:56","slug":"%e3%80%90java%e3%80%91%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%8b%bc%e6%8e%a5%e5%85%a8%e8%a7%a3%e6%9e%90%ef%bc%9a%e4%bb%8e%e5%8e%9f%e7%90%86%e5%88%b0%e5%ae%9e%e6%88%98%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/yunyanglib.cn\/?p=1133","title":{"rendered":"\u3010Java\u3011\u5b57\u7b26\u4e32\u62fc\u63a5\u5168\u89e3\u6790\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u4f18\u5316"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5927\u5bb6\u597d\uff0c\u6211\u662f\u4e91\u626c\uff5e \u6700\u8fd1\u5728\u9879\u76ee\u4e2d\u53d1\u73b0\u5f88\u591a\u5c0f\u4f19\u4f34\u5bf9 Java \u5b57\u7b26\u4e32\u62fc\u63a5\u7684\u7528\u6cd5\u8fd8\u5b58\u5728\u4e00\u4e9b\u8bef\u533a\uff0c\u6bd4\u5982\u5faa\u73af\u4e2d\u6ee5\u7528<code>+<\/code>\u53f7\u64cd\u4f5c\u7b26\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\uff0c\u6216\u8005\u4e0d\u6e05\u695a\u4e0d\u540c\u62fc\u63a5\u65b9\u5f0f\u7684\u9002\u7528\u573a\u666f\u3002\u4eca\u5929\u5c31\u6765\u7cfb\u7edf\u68b3\u7406\u4e00\u4e0b Java \u4e2d\u5b57\u7b26\u4e32\u62fc\u63a5\u7684\u51e0\u79cd\u6838\u5fc3\u65b9\u6cd5\uff0c\u4ece\u5e95\u5c42\u539f\u7406\u5230\u4ee3\u7801\u5b9e\u6218\uff0c\u5e2e\u5927\u5bb6\u5f7b\u5e95\u641e\u61c2\u8fd9\u4e2a\u57fa\u7840\u5374\u5173\u952e\u7684\u77e5\u8bc6\u70b9\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001<code>+<\/code>\u53f7\u64cd\u4f5c\u7b26\uff1a\u8bed\u6cd5\u7cd6\u7684\u5e95\u5c42\u771f\u76f8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u6700\u5e38\u7528\u7684\u5b57\u7b26\u4e32\u62fc\u63a5\u65b9\u5f0f\u5c31\u662f<code>+<\/code>\u53f7\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String str = \"Hello\" + \" World\" + \"!\";\nSystem.out.println(str); \/\/ \u8f93\u51fa\uff1aHello World!\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u5f88\u591a\u4eba\u4e0d\u77e5\u9053\uff0c<code>+<\/code>\u53f7\u5176\u5b9e\u662f Java \u63d0\u4f9b\u7684<strong>\u8bed\u6cd5\u7cd6<\/strong>\uff0c\u7f16\u8bd1\u5668\u4f1a\u5728\u7f16\u8bd1\u9636\u6bb5\u5bf9\u5176\u8fdb\u884c\u4f18\u5316\u3002\u6bd4\u5982\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u7f16\u8bd1\u540e\u4f1a\u88ab\u8f6c\u6362\u6210\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String str = new StringBuilder().append(\"Hello\")\n                                .append(\" World\")\n                                .append(\"!\").toString();\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u76f4\u63a5\u4f7f\u7528<code>+<\/code>\u53f7\u62fc\u63a5\u5b57\u7b26\u4e32\u65f6\uff0c\u6027\u80fd\u5e76\u6ca1\u6709\u60f3\u8c61\u4e2d\u90a3\u4e48\u5dee \u2014\u2014 \u56e0\u4e3a\u7f16\u8bd1\u5668\u5df2\u7ecf\u5e2e\u6211\u4eec\u4f18\u5316\u6210\u4e86<code>StringBuilder<\/code>\u7684<code>append<\/code>\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8fc7\u6709\u4e2a\u7279\u6b8a\u60c5\u51b5\uff1a\u5982\u679c<code>+<\/code>\u53f7\u8fde\u63a5\u7684\u4e24\u4e2a\u64cd\u4f5c\u6570\u90fd\u662f<strong>\u7f16\u8bd1\u65f6\u5e38\u91cf<\/strong>\uff0c\u7f16\u8bd1\u5668\u4f1a\u76f4\u63a5\u5728\u7f16\u8bd1\u9636\u6bb5\u5b8c\u6210\u62fc\u63a5\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u7f16\u8bd1\u65f6\u5e38\u91cf\u62fc\u63a5\uff0c\u76f4\u63a5\u4f18\u5316\u4e3a\u5b57\u7b26\u4e32\u5e38\u91cf\"11\"\nString numStr = 11 + \"\";\n\/\/ \u7b49\u540c\u4e8e String numStr = \"11\";\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u60c5\u51b5\u4e0d\u4f1a\u521b\u5efa<code>StringBuilder<\/code>\u5bf9\u8c61\uff0c\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u5faa\u73af\u62fc\u63a5\uff1a<code>+<\/code>\u53f7 vs <code>StringBuilder.append<\/code><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136<code>+<\/code>\u53f7\u5728\u5355\u6b21\u62fc\u63a5\u65f6\u6027\u80fd\u4e0d\u9519\uff0c\u4f46\u5728<strong>\u5faa\u73af\u4f53\u5185<\/strong>\u4f7f\u7528\u4f1a\u51fa\u5927\u95ee\u9898\uff01\u6bd4\u5982\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u9519\u8bef\u793a\u8303\uff1a\u5faa\u73af\u4e2d\u4f7f\u7528+\u53f7\u62fc\u63a5\nString result = \"\";\nfor (int i = 0; i&lt; 1000; i++) {\n    result += \"num\" + i; \/\/ \u6bcf\u6b21\u5faa\u73af\u90fd\u4f1a\u521b\u5efa\u65b0\u7684StringBuilder\u5bf9\u8c61\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48\u8bf4\u8fd9\u662f\u9519\u8bef\u7684\uff1f\u56e0\u4e3a\u6bcf\u6b21\u6267\u884c<code>result += ...<\/code>\u65f6\uff0cJava \u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684<code>StringBuilder<\/code>\u5bf9\u8c61\uff0c\u62fc\u63a5\u540e\u518d\u8f6c\u6210<code>String<\/code>\u3002\u5faa\u73af 1000 \u6b21\u5c31\u4f1a\u521b\u5efa 1000 \u4e2a<code>StringBuilder<\/code>\u548c<code>String<\/code>\u5bf9\u8c61\uff0c\u4e0d\u4ec5\u5360\u7528\u5927\u91cf\u5185\u5b58\uff0c\u8fd8\u4f1a\u89e6\u53d1\u9891\u7e41\u7684\u5783\u573e\u56de\u6536\uff08GC\uff09\uff0c\u4e25\u91cd\u5f71\u54cd\u6027\u80fd\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6b63\u786e\u5199\u6cd5<\/strong>\uff1a\u5728\u5faa\u73af\u5916\u90e8\u521b\u5efa<code>StringBuilder<\/code>\u5bf9\u8c61\uff0c\u5faa\u73af\u5185\u4ec5\u8c03\u7528<code>append<\/code>\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u6b63\u786e\u793a\u8303\uff1a\u5faa\u73af\u4e2d\u4f7f\u7528StringBuilder.append\nStringBuilder sb = new StringBuilder();\nfor (int i = 0; i&lt; 1000; i++) {\n    sb.append(\"num\").append(i); \/\/ \u4ec5\u521b\u5efa1\u4e2aStringBuilder\u5bf9\u8c61\n}\nString result = sb.toString();\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u6837\u53ea\u4f1a\u521b\u5efa\u4e00\u4e2a<code>StringBuilder<\/code>\u5bf9\u8c61\uff0c\u6240\u6709\u62fc\u63a5\u64cd\u4f5c\u90fd\u5728\u540c\u4e00\u4e2a\u5bf9\u8c61\u4e2d\u8fdb\u884c\uff0c\u6027\u80fd\u5927\u5e45\u63d0\u5347\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001<code>StringBuilder.append<\/code>\u6e90\u7801\u6df1\u5ea6\u89e3\u6790<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48<code>append<\/code>\u65b9\u6cd5\u6548\u7387\u8fd9\u4e48\u9ad8\uff1f\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u5176\u5e95\u5c42\u5b9e\u73b0\uff08\u57fa\u4e8e JDK 11\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ StringBuilder\u7684append\u65b9\u6cd5\uff08\u7ee7\u627f\u81eaAbstractStringBuilder\uff09\npublic StringBuilder append(String str) {\n    super.append(str);\n    return this;\n}\n\n\/\/ \u7236\u7c7bAbstractStringBuilder\u7684\u6838\u5fc3\u5b9e\u73b0\npublic AbstractStringBuilder append(String str) {\n    if (str == null) {\n        return appendNull(); \/\/ \u5904\u7406null\u503c\uff0c\u8f6c\u4e3a\u5b57\u7b26\u4e32\"null\"\n    }\n    int len = str.length();\n    ensureCapacityInternal(count + len); \/\/ \u6269\u5bb9\u68c0\u67e5\n    str.getChars(0, len, value, count); \/\/ \u590d\u5236\u5b57\u7b26\u5230\u76ee\u6807\u6570\u7ec4\n    count += len; \/\/ \u66f4\u65b0\u5b57\u7b26\u957f\u5ea6\n    return this;\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5173\u952e\u6b65\u9aa4\u62c6\u89e3\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>null \u503c\u5904\u7406<\/strong>\uff1a\u5982\u679c\u62fc\u63a5\u7684\u5b57\u7b26\u4e32\u662f<code>null<\/code>\uff0c\u4f1a\u81ea\u52a8\u8f6c\u4e3a &#8220;null&#8221;\uff08\u8fd9\u548c<code>+<\/code>\u53f7\u64cd\u4f5c\u7b26\u7684\u884c\u4e3a\u4e00\u81f4\uff09\uff1b<\/li>\n\n\n\n<li><strong>\u6269\u5bb9\u68c0\u67e5<\/strong>\uff1a<code>StringBuilder<\/code>\u5185\u90e8\u7528\u5b57\u7b26\u6570\u7ec4<code>value<\/code>\u5b58\u50a8\u5b57\u7b26\u4e32\uff0c<code>ensureCapacityInternal<\/code>\u4f1a\u5224\u65ad\u62fc\u63a5\u540e\u7684\u957f\u5ea6\u662f\u5426\u8d85\u8fc7\u6570\u7ec4\u5bb9\u91cf\uff0c\u5982\u679c\u8d85\u8fc7\u5219\u8fdb\u884c\u6269\u5bb9\uff08\u9ed8\u8ba4\u6269\u5bb9\u4e3a\u539f\u5bb9\u91cf\u7684 2 \u500d + 2\uff09\uff1b<\/li>\n\n\n\n<li><strong>\u5b57\u7b26\u590d\u5236<\/strong>\uff1a\u901a\u8fc7<code>str.getChars<\/code>\u76f4\u63a5\u5c06\u62fc\u63a5\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u590d\u5236\u5230\u76ee\u6807\u6570\u7ec4\uff0c\u907f\u514d\u521b\u5efa\u65b0\u5bf9\u8c61\uff1b<\/li>\n\n\n\n<li><strong>\u957f\u5ea6\u66f4\u65b0<\/strong>\uff1a\u76f4\u63a5\u4fee\u6539<code>count<\/code>\u53d8\u91cf\u8bb0\u5f55\u5f53\u524d\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u65e0\u9700\u989d\u5916\u8ba1\u7b97\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u57fa\u4e8e\u6570\u7ec4\u7684\u76f4\u63a5\u64cd\u4f5c\uff0c\u662f<code>StringBuilder<\/code>\u9ad8\u6548\u7684\u6838\u5fc3\u539f\u56e0\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u5176\u4ed6\u62fc\u63a5\u65b9\u5f0f\uff1a<code>concat<\/code>\u3001<code>join<\/code>\u4e0e<code>StringUtils.join<\/code><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86\u4e0a\u8ff0\u4e24\u79cd\u6838\u5fc3\u65b9\u5f0f\uff0cJava \u8fd8\u63d0\u4f9b\u4e86\u5176\u4ed6\u51e0\u79cd\u5b9e\u7528\u7684\u62fc\u63a5\u65b9\u6cd5\uff0c\u6211\u4eec\u6765\u9010\u4e00\u5206\u6790\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <code>String.concat<\/code>\u65b9\u6cd5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>concat<\/code>\u65b9\u6cd5\u662f<code>String<\/code>\u7c7b\u81ea\u5e26\u7684\u62fc\u63a5\u65b9\u6cd5\uff0c\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String str1 = \"Hello\";\nString str2 = \"World\";\nString result = str1.concat(\" \").concat(str2); \/\/ \u8f93\u51fa\uff1aHello World\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u6e90\u7801\u5b9e\u73b0\u6bd4\u8f83\u7b80\u5355\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public String concat(String str) {\n    int otherLen = str.length();\n    if (otherLen == 0) {\n        return this; \/\/ \u62fc\u63a5\u7a7a\u5b57\u7b26\u4e32\u65f6\uff0c\u76f4\u63a5\u8fd4\u56de\u539f\u5bf9\u8c61\n    }\n    int len = value.length;\n    char&#91;] buf = Arrays.copyOf(value, len + otherLen);\n    str.getChars(buf, len);\n    return new String(buf, true);\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4f18\u7f3a\u70b9<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f18\u70b9\uff1a\u62fc\u63a5\u7a7a\u5b57\u7b26\u4e32\u65f6\u6548\u7387\u6781\u9ad8\uff08\u76f4\u63a5\u8fd4\u56de\u539f\u5bf9\u8c61\uff0c\u65e0\u9700\u521b\u5efa\u65b0\u5b57\u7b26\u4e32\uff09\uff1b<\/li>\n\n\n\n<li>\u7f3a\u70b9\uff1a\n<ul class=\"wp-block-list\">\n<li>\u9047\u5230<code>null<\/code>\u4f1a\u629b\u51fa<code>NullPointerException<\/code>\uff08<code>+<\/code>\u53f7\u548c<code>StringBuilder<\/code>\u4e0d\u4f1a\uff09\uff1b<\/li>\n\n\n\n<li>\u591a\u6b21\u62fc\u63a5\u65f6\u4f1a\u521b\u5efa\u5927\u91cf\u4e2d\u95f4\u5b57\u7b26\u4e32\u5bf9\u8c61\uff0c\u6027\u80fd\u4e0d\u5982<code>StringBuilder<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <code>String.join<\/code>\u65b9\u6cd5\uff08Java 8+\uff09<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>String.join<\/code>\u662f Java 8 \u65b0\u589e\u7684\u9759\u6001\u65b9\u6cd5\uff0c\u652f\u6301\u7528\u6307\u5b9a\u5206\u9694\u7b26\u62fc\u63a5\u5b57\u7b26\u4e32\u6570\u7ec4\u6216\u96c6\u5408\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u62fc\u63a5\u5b57\u7b26\u4e32\u6570\u7ec4\nString&#91;] arr = {\"Java\", \"String\", \"Concatenation\"};\nString result1 = String.join(\"-\", arr); \/\/ \u8f93\u51fa\uff1aJava-String-Concatenation\n\n\/\/ \u62fc\u63a5\u96c6\u5408\nList&lt;String> list = Arrays.asList(\"Spring\", \"Boot\", \"2.x\");\nString result2 = String.join(\" \", list); \/\/ \u8f93\u51fa\uff1aSpring Boot 2.x\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u5e95\u5c42\u5b9e\u73b0\u662f\u901a\u8fc7<code>StringJoiner<\/code>\uff08\u672c\u8d28\u4e5f\u662f\u57fa\u4e8e<code>StringBuilder<\/code>\uff09\uff0c\u6e90\u7801\u7b80\u5316\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static String join(CharSequence delimiter, CharSequence... elements) {\n    StringJoiner joiner = new StringJoiner(delimiter);\n    for (CharSequence cs : elements) {\n        joiner.add(cs);\n    }\n    return joiner.toString();\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a\u9700\u8981\u7ed9\u591a\u4e2a\u5b57\u7b26\u4e32\u6dfb\u52a0\u7edf\u4e00\u5206\u9694\u7b26\u65f6\uff08\u6bd4\u5982\u62fc\u63a5 URL \u53c2\u6570\u3001\u65e5\u5fd7\u4fe1\u606f\uff09\uff0c\u4ee3\u7801\u7b80\u6d01\u4e14\u6613\u8bfb\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <code>StringUtils.join<\/code>\u65b9\u6cd5\uff08Apache Commons Lang3\uff09<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u9879\u76ee\u4e2d\u5f15\u5165\u4e86<code>Apache Commons Lang3<\/code>\u4f9d\u8d56\uff0c\u63a8\u8350\u4f7f\u7528<code>StringUtils.join<\/code>\u65b9\u6cd5\uff0c\u5b83\u89e3\u51b3\u4e86<code>null<\/code>\u503c\u5904\u7406\u95ee\u9898\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5f15\u5165\u4f9d\u8d56\uff08Maven\uff09\n&lt;!-- Source: https:\/\/mvnrepository.com\/artifact\/org.apache.commons\/commons-lang3 -->\n&lt;dependency>\n    &lt;groupId>org.apache.commons&lt;\/groupId>\n    &lt;artifactId>commons-lang3&lt;\/artifactId>\n    &lt;version>3.20.0&lt;\/version>\n    &lt;scope>compile&lt;\/scope>\n&lt;\/dependency>\n\n\/\/ \u4ee3\u7801\u793a\u4f8b\uff1a\u65e0\u9700\u62c5\u5fc3null\u503c\nString str1 = \"Hello\";\nString str2 = null;\nString str3 = \"World\";\nString result = StringUtils.join(str1, str2, str3); \/\/ \u8f93\u51fa\uff1aHelloWorld\n\/\/ \u5e26\u5206\u9694\u7b26\u7684\u62fc\u63a5\nString resultWithDelim = StringUtils.join(new String&#91;]{str1, str2, str3}, \"-\"); \/\/ \u8f93\u51fa\uff1aHello-World\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>StringUtils.join<\/code>\u7684\u5e95\u5c42\u4e5f\u662f\u4f7f\u7528<code>StringBuilder<\/code>\uff0c\u5e76\u4e14\u4f1a\u81ea\u52a8\u5ffd\u7565<code>null<\/code>\u503c\uff0c\u907f\u514d\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u662f\u5b9e\u9645\u9879\u76ee\u4e2d\u975e\u5e38\u5e38\u7528\u7684\u5de5\u5177\u65b9\u6cd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u5b9e\u6218\u4f18\u5316\u5efa\u8bae\u603b\u7ed3<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5355\u6b21\u62fc\u63a5<\/strong>\uff1a\u76f4\u63a5\u4f7f\u7528<code>+<\/code>\u53f7\uff08\u7f16\u8bd1\u5668\u4f18\u5316\u4e3a<code>StringBuilder<\/code>\uff0c\u4ee3\u7801\u7b80\u6d01\uff09\uff1b<\/li>\n\n\n\n<li><strong>\u5faa\u73af\u62fc\u63a5<\/strong>\uff1a\u5fc5\u987b\u4f7f\u7528<code>StringBuilder.append<\/code>\uff08\u907f\u514d\u521b\u5efa\u5927\u91cf\u4e2d\u95f4\u5bf9\u8c61\uff09\uff1b<\/li>\n\n\n\n<li><strong>\u591a\u5b57\u7b26\u4e32\u5206\u9694\u62fc\u63a5<\/strong>\uff1a\u4f7f\u7528<code>String.join<\/code>\uff08Java 8+\uff09\u6216<code>StringUtils.join<\/code>\uff08\u9700\u5f15\u5165\u4f9d\u8d56\uff09\uff1b<\/li>\n\n\n\n<li><strong>\u62fc\u63a5\u7a7a\u5b57\u7b26\u4e32<\/strong>\uff1a\u4f18\u5148\u4f7f\u7528<code>concat<\/code>\u65b9\u6cd5\uff08\u6548\u7387\u6700\u9ad8\uff09\uff1b<\/li>\n\n\n\n<li><strong>\u5904\u7406 null \u503c<\/strong>\uff1a\u4f7f\u7528<code>StringUtils.join<\/code>\uff08\u81ea\u52a8\u5ffd\u7565 null\uff09\u6216\u624b\u52a8\u5224\u65ad\uff08<code>str == null ? \"\" : str<\/code>\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u6700\u540e<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b57\u7b26\u4e32\u62fc\u63a5\u770b\u4f3c\u7b80\u5355\uff0c\u4f46\u80cc\u540e\u6d89\u53ca\u7f16\u8bd1\u5668\u4f18\u5316\u3001\u5185\u5b58\u5206\u914d\u3001\u6027\u80fd\u635f\u8017\u7b49\u591a\u4e2a\u77e5\u8bc6\u70b9\u3002\u638c\u63e1\u4e0d\u540c\u62fc\u63a5\u65b9\u5f0f\u7684\u5e95\u5c42\u539f\u7406\u548c\u9002\u7528\u573a\u666f\uff0c\u80fd\u5e2e\u52a9\u6211\u4eec\u5199\u51fa\u66f4\u9ad8\u6548\u3001\u66f4\u5065\u58ee\u7684\u4ee3\u7801\u3002\u5982\u679c\u5927\u5bb6\u6709\u5176\u4ed6\u5173\u4e8e\u5b57\u7b26\u4e32\u5904\u7406\u7684\u7591\u95ee\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u8ba8\u8bba\uff5e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u4e91\u626c\uff5e \u6700\u8fd1\u5728\u9879\u76ee\u4e2d\u53d1\u73b0\u5f88\u591a\u5c0f\u4f19\u4f34\u5bf9 Java \u5b57\u7b26\u4e32\u62fc\u63a5\u7684\u7528\u6cd5\u8fd8\u5b58\u5728\u4e00\u4e9b\u8bef\u533a\uff0c\u6bd4\u5982\u5faa\u73af\u4e2d\u6ee5\u7528+\u53f7<\/p>\n<div class=\"more-link\">\n\t\t\t\t <a href=\"https:\/\/yunyanglib.cn\/?p=1133\" class=\"link-btn theme-btn\"><span>Read More <\/span> <i class=\"fa fa-caret-right\"><\/i><\/a>\n\t\t\t<\/div>\n","protected":false},"author":1,"featured_media":1136,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[15],"class_list":["post-1133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java"],"_links":{"self":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/1133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1133"}],"version-history":[{"count":2,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/1133\/revisions"}],"predecessor-version":[{"id":1135,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/1133\/revisions\/1135"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/media\/1136"}],"wp:attachment":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}