{"id":8912,"date":"2022-12-01T10:07:56","date_gmt":"2022-12-01T02:07:56","guid":{"rendered":"http:\/\/123.57.164.21\/?p=8912"},"modified":"2022-12-01T10:07:56","modified_gmt":"2022-12-01T02:07:56","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88stringbuilder%e7%ba%bf%e7%a8%8b%e4%b8%8d%e5%ae%89%e5%85%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=8912","title":{"rendered":"\u4e3a\u4ec0\u4e48StringBuilder\u7ebf\u7a0b\u4e0d\u5b89\u5168\uff1f"},"content":{"rendered":"\n<p><strong>\u4e00\u3001\u73b0\u8c61\u5206\u6790<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5148\u4e0a\u7ed3\u8bba\uff0cStringBuilder\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0cStringBuffer\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u8fd9\u7bc7\u6587\u7ae0\u5c31\u63a2\u7a76\u4e00\u4e0b\u5e95\u5c42\u539f\u7406\u3002<\/p>\n\n\n\n<p>\u5728\u5206\u6790\u8fd9\u4e2a\u95ee\u9898\u4e4b\u524d\u8981\u77e5\u9053StringBuilder\u548cStringBuffer\u7684\u5185\u90e8\u5b9e\u73b0\u8ddfString\u7c7b\u4e00\u6837\uff0c\u90fd\u662f\u901a\u8fc7\u4e00\u4e2achar\u6570\u7ec4\u5b58\u50a8\u5b57\u7b26\u4e32\u7684\uff0c\u4e0d\u540c\u7684\u662fString\u7c7b\u91cc\u9762\u7684char\u6570\u7ec4\u662ffinal\u4fee\u9970\u7684\uff0c\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u800cStringBuilder\u548cStringBuffer\u7684char\u6570\u7ec4\u662f\u53ef\u53d8\u7684\uff0c\u6ca1\u6709\u4f7f\u7528final\u4fee\u9970\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u901a\u8fc7\u4e00\u6bb5\u4ee3\u7801\u53bb\u770b\u4e00\u4e0b\u591a\u7ebf\u7a0b\u64cd\u4f5cStringBuilder\u5bf9\u8c61\u4f1a\u51fa\u73b0\u4ec0\u4e48\u95ee\u9898\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class StringBuilderDemo {\n\n    public static void main(String[] args) throws InterruptedException {\n        StringBuilder stringBuilder = new StringBuilder();\n        for (int i = 0; i &lt; 10; i++){\n            new Thread(new Runnable() {\n                @Override\n                public void run() {\n                    for (int j = 0; j &lt; 1000; j++){\n                        stringBuilder.append(\"a\");\n                    }\n                }\n            }).start();\n        }\n\n        Thread.sleep(100);\n        System.out.println(stringBuilder.length());\n    }\n}\n<\/pre>\n\n\n\n<p><br>\u8fd9\u6bb5\u4ee3\u7801\u521b\u5efa\u4e8610\u4e2a\u7ebf\u7a0b\uff0c\u6bcf\u4e2a\u7ebf\u7a0b\u5faa\u73af1000\u6b21\u5f80StringBuilder\u5bf9\u8c61\u91cc\u9762append\u5b57\u7b26\u3002\u6b63\u5e38\u60c5\u51b5\u4e0b\u4ee3\u7801\u5e94\u8be5\u8f93\u51fa10000\uff0c\u4f46\u662f\u5b9e\u9645\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1024x206.png\" alt=\"\" class=\"wp-image-8913\" width=\"596\" height=\"119\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1024x206.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-300x60.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-768x154.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-830x167.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-230x46.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-350x70.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-480x97.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247.png 1372w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><\/figure><\/div>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u8f93\u51fa\u4e86 \u201c9326\u201d\uff0c\u5c0f\u4e8e\u9884\u671f\u768410000\uff0c\u5e76\u4e14\u8fd8\u629b\u51fa\u4e86\u4e00\u4e2a <code>ArrayIndexOutOfBoundsException<\/code> \u5f02\u5e38\uff08\u5f02\u5e38\u4e0d\u662f\u5fc5\u73b0\uff09\u3002<\/p>\n\n\n\n<p><strong>\u4e8c\u3001\u4e3a\u4ec0\u4e48\u8f93\u51fa\u503c\u8ddf\u9884\u671f\u503c\u4e0d\u4e00\u6837<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5148\u770b\u4e00\u4e0bStringBuilder\u7684\u4e24\u4e2a\u6210\u5458\u53d8\u91cf\uff08\u8fd9\u4e24\u4e2a\u6210\u5458\u53d8\u91cf\u5b9e\u9645\u4e0a\u662f\u5b9a\u4e49\u5728AbstractStringBuilder\u91cc\u9762\u7684\uff0cStringBuilder\u548cStringBuffer\u90fd\u7ee7\u627f\u4e86AbstractStringBuilder\uff09<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u5b58\u50a8\u5b57\u7b26\u4e32\u7684\u5177\u4f53\u5185\u5bb9\nchar[] value;\n\n\/\/\u5df2\u7ecf\u4f7f\u7528\u7684\u5b57\u7b26\u6570\u7ec4\u7684\u6570\u91cf\nint count;<\/pre>\n\n\n\n<p>\u518d\u770bStringBuilder\u7684 <code>append()<\/code> \u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Override\npublic StringBuilder append(String str) {\n    super.append(str);\n    return this;\n}<\/pre>\n\n\n\n<p>StringBuilder\u7684 <code>append()<\/code> \u65b9\u6cd5\u8c03\u7528\u7236\u7c7bAbstractStringBuilder\u7684 <code>append()<\/code> \u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">1.public AbstractStringBuilder append(String str) {\n2.    if (str == null)\n3.        return appendNull();\n4.    int len = str.length();\n5.    ensureCapacityInternal(count + len);\n6.    str.getChars(0, len, value, count);\n7.    count += len;\n8.    return this;\n9.}\n<\/pre>\n\n\n\n<p>\u5148\u4e0d\u7ba1\u4ee3\u7801\u7684\u7b2c\u4e94\u884c\u548c\u7b2c\u516d\u884c\u5e72\u4e86\u4ec0\u4e48\uff0c\u76f4\u63a5\u770b\u7b2c\u4e03\u884c\uff0ccount += len \u4e0d\u662f\u4e00\u4e2a\u539f\u5b50\u64cd\u4f5c\u3002\u5047\u8bbe\u8fd9\u4e2a\u65f6\u5019count\u503c\u4e3a10\uff0clen\u503c\u4e3a1\uff0c\u4e24\u4e2a\u7ebf\u7a0b\u540c\u65f6\u6267\u884c\u5230\u4e86\u7b2c\u4e03\u884c\uff0c\u62ff\u5230\u7684count\u503c\u90fd\u662f10\uff0c\u6267\u884c\u5b8c\u52a0\u6cd5\u8fd0\u7b97\u540e\u5c06\u7ed3\u679c\u8d4b\u503c\u7ed9count\uff0c\u6240\u4ee5\u4e24\u4e2a\u7ebf\u7a0b\u6267\u884c\u5b8c\u540ecount\u503c\u4e3a11\uff0c\u800c\u4e0d\u662f12\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u6d4b\u8bd5\u4ee3\u7801\u8f93\u51fa\u7684\u503c\u8981\u6bd410000\u5c0f\u7684\u539f\u56e0\u3002<\/p>\n\n\n\n<p><strong>\u4e09\u3001\u4e3a\u4ec0\u4e48\u4f1a\u629b\u51fa\u5f02\u5e38<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u56de\u770bAbstractStringBuilder\u7684 <code>append()<\/code> \u65b9\u6cd5\u6e90\u7801\u7684\u7b2c\u4e94\u884c\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">1.public AbstractStringBuilder append(String str) {\n      \/\/...\n4.    int len = str.length();\n5.    ensureCapacityInternal(count + len);\n      \/\/...\n}\n<\/pre>\n\n\n\n<p><code>ensureCapacityInternal()<\/code> \u65b9\u6cd5\u7528\u6765\u68c0\u67e5StringBuilder\u5bf9\u8c61\u7684\u539fchar\u6570\u7ec4\u7684\u5bb9\u91cf\u80fd\u4e0d\u80fd\u5bb9\u4e0b\u65b0\u7684\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u5bb9\u4e0d\u4e0b\u5c31\u8c03\u7528 <code>expandCapacity()<\/code> \u65b9\u6cd5\u5bf9char\u6570\u7ec4\u8fdb\u884c\u6269\u5bb9\uff0c\u90e8\u5206\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u53c2\u6570minimumCapacity\u662f\u6570\u7ec4\u4e2d\u5df2\u5360\u7528\u7684+\u5c06\u8981\u5360\u7528\u7684\u548c\nprivate void ensureCapacityInternal(int minimumCapacity) {\n    \/\/ overflow-conscious code\n    if (minimumCapacity - value.length > 0)\n        expandCapacity(minimumCapacity);\n}\n<\/pre>\n\n\n\n<p>\u6269\u5bb9\u7684\u903b\u8f91\u5c31\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684char\u6570\u7ec4\uff0c\u65b0\u7684char\u6570\u7ec4\u7684\u5bb9\u91cf\u662f\u539f\u6765char\u6570\u7ec4\u7684\u4e24\u500d\u518d\u52a02\uff0c\u518d\u901a\u8fc7 <code>System.arryCopy()<\/code> \u65b9\u6cd5\u5c06\u539f\u6570\u7ec4\u7684\u5185\u5bb9\u590d\u5236\u5230\u6269\u5bb9\u540e\u7684\u65b0\u6570\u7ec4\uff0c\u6700\u540e\u5c06\u6307\u9488\u6307\u5411\u65b0\u6570\u7ec4\uff0c\u90e8\u5206\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void expandCapacity(int minimumCapacity) {\n    \n    \/\/\u8ba1\u7b97\u65b0\u7684\u5bb9\u91cf\n    int newCapacity = value.length * 2 + 2;\n    \n    \/\/\u4e2d\u95f4\u7701\u7565\u4e86\u4e00\u4e9b\u68c0\u67e5\u903b\u8f91\n    \/\/...\n    value = Arrays.copyOf(value, newCapacity);\n}\n<\/pre>\n\n\n\n<p><code>Arrys.copyOf()<\/code> \u65b9\u6cd5\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public static char[] copyOf(char[] original, int newLength) {\n    \n    char[] copy = new char[newLength];\n    \n    \/\/\u62f7\u8d1d\u6570\u7ec4\n    System.arraycopy(original, 0, copy, 0,\n                     Math.min(original.length, newLength));\n    return copy;\n}\n<\/pre>\n\n\n\n<p>AbstractStringBuilder\u7684 <code>append()<\/code> \u65b9\u6cd5\u6e90\u7801\u7684\u7b2c\u516d\u884c\uff0c\u662f\u5c06\u53c2\u6570String\u5bf9\u8c61\u91cc\u9762\u7684char\u6570\u7ec4\u91cc\u9762\u7684\u5185\u5bb9\u62f7\u8d1d\u5230StringBuilder\u5bf9\u8c61\u7684char\u6570\u7ec4\u91cc\u9762\uff0c\u7b2c\u516d\u884c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">1.public AbstractStringBuilder append(String str) {\n      \/\/...\n4.    int len = str.length();\n5.    ensureCapacityInternal(count + len);\n6.    str.getChars(0, len, value, count);\n      \/\/...\n}\n<\/pre>\n\n\n\n<p><code>getChars()<\/code> \u65b9\u6cd5\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u53c2\u65701\u30012\u8868\u793aString\u5bf9\u8c61\u7684char\u6570\u7ec4\u7684\u8d77\u59cb\u4f4d\u7f6e\u548c\u7ec8\u6b62\u4f4d\u7f6e\n\/\/\u53c2\u65703\u30014\u8868\u793aStringBuilder\u5bf9\u8c61\u7684char\u6570\u7ec4\u548c\u5c06\u8981\u6dfb\u52a0\u65b0\u5143\u7d20\u7684\u8d77\u59cb\u4f4d\u7f6e\npublic void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {\n    \/\/\u4e2d\u95f4\u7701\u7565\u4e86\u4e00\u4e9b\u68c0\u67e5\n    \/\/...\n    System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);\n}\n<\/pre>\n\n\n\n<p>\u62f7\u8d1d\u6d41\u7a0b\u89c1\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1-1024x416.png\" alt=\"\" class=\"wp-image-8915\" width=\"477\" height=\"194\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1-1024x416.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1-300x122.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1-768x312.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1-830x338.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1-230x94.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1-350x142.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1-480x195.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-1.png 1264w\" sizes=\"(max-width: 477px) 100vw, 477px\" \/><\/figure><\/div>\n\n\n\n<p>\u5047\u8bbe\u73b0\u5728\u6709\u4e24\u4e2a\u7ebf\u7a0b\u540c\u65f6\u6267\u884c\u4e86StringBuilder\u7684 <code>append()<\/code> \u65b9\u6cd5\uff0c\u4e24\u4e2a\u7ebf\u7a0b\u90fd\u6267\u884c\u5b8c\u4e86\u7b2c\u4e94\u884c\u7684 <code>ensureCapacityInternal()<\/code> \u65b9\u6cd5\uff0c\u6b64\u523bcount=5\uff0c\u8868\u793a\u65b0\u5143\u7d20\u5c06\u8981\u4ece5\u4f4d\u7f6e\u5f00\u59cb\u6dfb\u52a0\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-2-1024x537.png\" alt=\"\" class=\"wp-image-8916\" width=\"419\" height=\"219\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-2-1024x537.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-2-300x157.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-2-768x403.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-2-830x435.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-2-230x121.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-2-350x183.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-2-480x252.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-2.png 1202w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><\/figure><\/div>\n\n\n\n<p>\u5047\u5982\u8fd9\u4e2a\u65f6\u5019\u7ebf\u7a0b1\u7684cpu\u65f6\u95f4\u7247\u7528\u5b8c\u4e86\uff0c\u7ebf\u7a0b2\u7ee7\u7eed\u6267\u884c\uff0c\u7ebf\u7a0b2\u6267\u884c\u5b8c\u6574\u4e2a <code>append()<\/code> \u65b9\u6cd5\u540ecount\u53d8\u62106\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-3.png\" alt=\"\" class=\"wp-image-8917\" width=\"276\" height=\"303\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-3.png 638w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-3-273x300.png 273w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-3-230x252.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-3-350x384.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-3-480x527.png 480w\" sizes=\"(max-width: 276px) 100vw, 276px\" \/><\/figure><\/div>\n\n\n\n<p>\u8fd9\u4e2a\u65f6\u5019\u7ebf\u7a0b1\u7ee7\u7eed\u6267\u884c\u7b2c\u516d\u884c\u7684 <code>str.getChars()<\/code> \u65b9\u6cd5\u62ff\u5230\u7684count\u503c\u5c31\u662f6\uff0c\u6267\u884cchar\u6570\u7ec4\u62f7\u8d1d\u65f6\u5c31\u4f1a\u629b\u51fa <code>ArrayIndexOutOfBoundsException<\/code> \u5f02\u5e38\u3002<\/p>\n\n\n\n<p><strong>\u56db\u3001StringBuffer\u7ebf\u7a0b\u5b89\u5168\u7684\u539f\u56e0<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5982\u679c\u5c06\u6d4b\u8bd5\u4ee3\u7801\u7684StringBuilder\u5bf9\u8c61\u6362\u6210StringBuffer\u5bf9\u8c61\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-4.png\" alt=\"\" class=\"wp-image-8918\" width=\"421\" height=\"75\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-4.png 714w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-4-300x54.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-4-230x41.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-4-350x63.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/12\/\u56fe\u7247-4-480x86.png 480w\" sizes=\"(max-width: 421px) 100vw, 421px\" \/><\/figure><\/div>\n\n\n\n<p>\u6ca1\u6709\u51fa\u73b0\u5f02\u5e38\uff0c\u4e14\u6309\u7167\u9884\u671f\u7ed3\u679c\u8f93\u51fa\u3002<\/p>\n\n\n\n<p>StringBuffer\u7684 <code>append()<\/code> \u65b9\u6cd5\u7684\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public synchronized StringBuffer append(String str) {\n    toStringCache = null;\n    super.append(str);\n    return this;\n}\n<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u53d1\u73b0\uff0cStringBuffer\u7ebf\u7a0b\u5b89\u5168\u7684\u539f\u56e0\u662f\u4f7f\u7528\u4e86 <code>synchronized<\/code> \u5173\u952e\u5b57\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u73b0\u8c61\u5206\u6790 \u5148\u4e0a\u7ed3\u8bba\uff0cStringBuilder\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0cStringBuffer\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u8fd9\u7bc7\u6587 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8912"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8912"}],"version-history":[{"count":2,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8912\/revisions"}],"predecessor-version":[{"id":8919,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8912\/revisions\/8919"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}