{"id":203753,"date":"2025-05-22T13:08:21","date_gmt":"2025-05-22T05:08:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203753\/"},"modified":"2025-05-22T13:08:21","modified_gmt":"2025-05-22T05:08:21","slug":"java-%e4%b8%ad%e8%bf%9e%e6%8e%a5%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%9a%84-asy-%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203753\/","title":{"rendered":"Java \u4e2d\u8fde\u63a5\u5b57\u7b26\u4e32\u7684 asy \u6280\u5de7"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Java \u4e2d\u8fde\u63a5\u5b57\u7b26\u4e32\u7684 asy \u6280\u5de7<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aJava \u4e2d\u8fde\u63a5\u5b57\u7b26\u4e32\u7684 asy \u6280\u5de7\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732198893673f41ed4263f.jpg\" class=\"aligncenter\"><\/p>\n<h2> 1. \u4f7f\u7528+\u8fd0\u7b97\u7b26 <\/h2>\n<p>+\u8fd0\u7b97\u7b26\u662fjava\u4e2d\u8fde\u63a5\u5b57\u7b26\u4e32\u6700\u7b80\u5355\u4e5f\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u3002\u5b83\u76f4\u89c2\u4e14\u6613\u4e8e\u7406\u89e3\uff0c\u4f7f\u5176\u6210\u4e3a\u521d\u5b66\u8005\u7684\u70ed\u95e8\u9009\u62e9\u3002 <\/p>\n<h3> 1.1 \u57fa\u672c\u793a\u4f8b <\/h3>\n<pre>string firstname = \"john\";\nstring lastname = \"doe\";\nstring fullname = firstname + \" \" + lastname;\nsystem.out.println(fullname);\n<\/pre>\n<p><strong>\u6f14\u793a\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>john doe\n<\/pre>\n<h3> 1.2 \u6027\u80fd\u8003\u8651 <\/h3>\n<p>\u867d\u7136 + \u8fd0\u7b97\u7b26\u5f88\u65b9\u4fbf\uff0c\u4f46\u5728\u5faa\u73af\u4e2d\u8fde\u63a5\u5927\u91cf\u5b57\u7b26\u4e32\u65f6\uff0c\u5b83\u53ef\u80fd\u4e0d\u662f\u6700\u6709\u6548\u7684\u9009\u62e9\u3002\u8fd9\u662f\u56e0\u4e3a\u5b83\u6bcf\u6b21\u8fde\u63a5\u65f6\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 string \u5bf9\u8c61\uff0c\u4ece\u800c\u5bfc\u81f4\u4e0d\u5fc5\u8981\u7684\u5185\u5b58\u4f7f\u7528\u3002 <\/p>\n<h3> 1.3 \u4f7f\u7528\u6848\u4f8b <\/h3>\n<ul>\n<li> <strong>\u7b80\u5355\u8fde\u63a5<\/strong>\uff1a\u5f53\u4f60\u53ea\u9700\u8981\u8fde\u63a5\u51e0\u4e2a\u5b57\u7b26\u4e32\u65f6\uff0c\u6027\u80fd\u4e0d\u662f\u95ee\u9898\u3002<\/li>\n<li> <strong>\u53ef\u8bfb\u6027<\/strong>\uff1a\u5f53\u60a8\u5e0c\u671b\u4ee3\u7801\u6613\u4e8e\u9605\u8bfb\u548c\u7406\u89e3\u65f6\u3002<\/li>\n<\/ul>\n<h3> 1.4 \u9650\u5236 <\/h3>\n<ul>\n<li> <strong>\u5185\u5b58\u4f7f\u7528<\/strong>\uff1a\u7531\u4e8e\u521b\u5efa\u591a\u4e2a string \u5bf9\u8c61\uff0c\u5927\u89c4\u6a21\u4e32\u8054\u6548\u7387\u4f4e\u4e0b\u3002<\/li>\n<li> <strong>\u6027\u80fd<\/strong>\uff1a\u53ef\u80fd\u5bfc\u81f4\u5faa\u73af\u6027\u80fd\u4e0b\u964d\u3002<\/li>\n<\/ul>\n<h2> 2.\u4f7f\u7528stringbuilder <\/h2>\n<p><strong>stringbuilder<\/strong> \u662f\u4e00\u4e2a\u53ef\u53d8\u7684\u5b57\u7b26\u5e8f\u5217\uff0c\u8fd9\u4f7f\u5f97\u5b83\u6210\u4e3a\u5b57\u7b26\u4e32\u8fde\u63a5\u7684\u66f4\u8282\u7701\u5185\u5b58\u7684\u9009\u62e9\uff0c\u7279\u522b\u662f\u5728\u5faa\u73af\u6216\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\u3002 <\/p>\n<h3> 2.1 \u57fa\u672c\u793a\u4f8b <\/h3>\n<pre>stringbuilder sb = new stringbuilder();\nsb.append(\"john\");\nsb.append(\" \");\nsb.append(\"doe\");\nstring fullname = sb.tostring();\nsystem.out.println(fullname);\n<\/pre>\n<p><strong>\u6f14\u793a\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>john doe\n<\/pre>\n<h3> 2.2 \u6027\u80fd\u8003\u8651 <\/h3>\n<p> \u5728\u5faa\u73af\u4e2d\u8fde\u63a5\u5b57\u7b26\u4e32\u6216\u5904\u7406\u5927\u5b57\u7b26\u4e32\u65f6\uff0c <\/p>\n<p><strong>stringbuilder<\/strong> \u6bd4 + \u8fd0\u7b97\u7b26\u66f4\u9ad8\u6548\u3002\u5b83\u4e0d\u4f1a\u521b\u5efa\u591a\u4e2a string \u5bf9\u8c61\uff0c\u8fd9\u4f7f\u5176\u6210\u4e3a\u6027\u80fd\u5173\u952e\u578b\u5e94\u7528\u7a0b\u5e8f\u7684\u66f4\u597d\u9009\u62e9\u3002 <\/p>\n<h3> 2.3 \u4f7f\u7528\u6848\u4f8b <\/h3>\n<ul>\n<li> <strong>\u5faa\u73af<\/strong> \uff1a\u5728\u5faa\u73af\u5185\u8fde\u63a5\u5b57\u7b26\u4e32\u65f6\u3002<\/li>\n<li> <strong>\u5927\u5b57\u7b26\u4e32<\/strong>\uff1a\u5904\u7406\u5927\u5b57\u7b26\u4e32\u6216\u591a\u4e2a\u4e32\u8054\u65f6\u3002<\/li>\n<\/ul>\n<h3> 2.4 \u9650\u5236 <\/h3>\n<p>\u7ebf\u7a0b\u5b89\u5168\uff1a<strong>stringbuilder<\/strong>\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002\u5982\u679c\u9700\u8981\u7ebf\u7a0b\u5b89\u5168\uff0c\u8bf7\u8003\u8651\u4f7f\u7528 <strong>stringbuffer<\/strong><\/p>\n<h2> 3.\u4f7f\u7528stringbuffer <\/h2>\n<p><strong>stringbuffer<\/strong> \u4e0e <strong>stringbuilder<\/strong> \u7c7b\u4f3c\uff0c\u4f46\u5b83\u662f\u540c\u6b65\u7684\uff0c\u4f7f\u5176\u7ebf\u7a0b\u5b89\u5168\u3002\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e2d\u5b89\u5168\u5730\u4f7f\u7528\u3002 <\/p>\n<p>3.1 \u57fa\u672c\u793a\u4f8b<\/p>\n<pre>stringbuffer sb = new stringbuffer();\nsb.append(\"john\");\nsb.append(\" \");\nsb.append(\"doe\");\nstring fullname = sb.tostring();\nsystem.out.println(fullname);\n<\/pre>\n<p><strong>\u6f14\u793a\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>john doe\n<\/pre>\n<h3> 3.2 \u6027\u80fd\u8003\u8651 <\/h3>\n<p><strong>stringbuffer<\/strong> \u63d0\u4f9b\u7ebf\u7a0b\u5b89\u5168\u6027\uff0c\u4f46\u4e0e <strong>stringbuilder<\/strong> \u76f8\u6bd4\uff0c\u6027\u80fd\u7565\u6709\u4e0b\u964d\u3002\u4ec5\u5f53\u8003\u8651\u7ebf\u7a0b\u5b89\u5168\u65f6\u624d\u4f7f\u7528 <strong>stringbuffer<\/strong>\u3002 <\/p>\n<h3> 3.3 \u4f7f\u7528\u6848\u4f8b <\/h3>\n<p>\u591a\u7ebf\u7a0b\u73af\u5883\uff1a\u5f53\u60a8\u9700\u8981\u4ee5\u7ebf\u7a0b\u5b89\u5168\u7684\u65b9\u5f0f\u8fde\u63a5\u5b57\u7b26\u4e32\u65f6\u3002 <\/p>\n<h3> 3.4 \u9650\u5236 <\/h3>\n<p>\u6027\u80fd\uff1a\u7531\u4e8e\u540c\u6b65\uff0c\u6bd4 <strong>stringbuilder<\/strong> \u7a0d\u6162\u3002 <\/p>\n<h2> 4. \u4f7f\u7528 string.join() <\/h2>\n<p><strong>string.join()<\/strong> \u662f\u4e00\u79cd\u9759\u6001\u65b9\u6cd5\uff0c\u5141\u8bb8\u60a8\u4f7f\u7528\u5206\u9694\u7b26\u8fde\u63a5\u6570\u7ec4\u6216\u5b57\u7b26\u4e32\u5217\u8868\u3002\u5f53\u60a8\u9700\u8981\u4f7f\u7528\u7279\u5b9a\u5206\u9694\u7b26\u8fde\u63a5\u591a\u4e2a\u5b57\u7b26\u4e32\u65f6\uff0c\u6b64\u65b9\u6cd5\u975e\u5e38\u65b9\u4fbf\u3002 <\/p>\n<h3> 4.1 \u57fa\u672c\u793a\u4f8b <\/h3>\n<pre>string[] names = {\"john\", \"doe\"};\nstring fullname = string.join(\" \", names);\nsystem.out.println(fullname);\n<\/pre>\n<p><strong>\u6f14\u793a\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>john doe\n<\/pre>\n<h3> 4.2 \u6027\u80fd\u8003\u8651 <\/h3>\n<p><strong>string.join()<\/strong> \u975e\u5e38\u9ad8\u6548\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e00\u79cd\u4f7f\u7528\u5206\u9694\u7b26\u8fde\u63a5\u5b57\u7b26\u4e32\u7684\u7b80\u6d01\u65b9\u6cd5\u3002\u5728\u5904\u7406\u5b57\u7b26\u4e32\u96c6\u5408\u6216\u6570\u7ec4\u65f6\u5b83\u7279\u522b\u6709\u7528\u3002 <\/p>\n<h3> 4.3 \u4f7f\u7528\u6848\u4f8b <\/h3>\n<ul>\n<li> <strong>\u5206\u9694\u5b57\u7b26\u4e32<\/strong> \uff1a\u5f53\u60a8\u9700\u8981\u4f7f\u7528\u5206\u9694\u7b26\uff08\u4f8b\u5982\u9017\u53f7\u3001\u7a7a\u683c\u6216\u8fde\u5b57\u7b26\uff09\u8fde\u63a5\u5b57\u7b26\u4e32\u65f6\u3002<\/li>\n<li> <strong>\u96c6\u5408<\/strong>\uff1a\u4f7f\u7528\u6570\u7ec4\u6216\u5b57\u7b26\u4e32\u5217\u8868\u65f6\u3002<\/li>\n<\/ul>\n<h3> 4.4 \u9650\u5236 <\/h3>\n<p><strong>\u56fa\u5b9a\u5206\u9694\u7b26<\/strong>\uff1a\u6700\u9002\u5408\u9700\u8981\u5728\u5b57\u7b26\u4e32\u4e4b\u95f4\u4f7f\u7528\u4e00\u81f4\u5206\u9694\u7b26\u7684\u60c5\u51b5\u3002 <\/p>\n<h2> 5. \u4f7f\u7528 string.format() <\/h2>\n<p>string.format() \u5141\u8bb8\u60a8\u5c06\u5b57\u7b26\u4e32\u4e0e\u5360\u4f4d\u7b26\u8fde\u63a5\u8d77\u6765\u3002\u5f53\u60a8\u9700\u8981\u52a8\u6001\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u65f6\uff0c\u6b64\u65b9\u6cd5\u975e\u5e38\u6709\u7528\u3002 <\/p>\n<h3> 5.1 \u57fa\u672c\u793a\u4f8b <\/h3>\n<pre>string firstname = \"john\";\nstring lastname = \"doe\";\nstring fullname = string.format(\"%s %s\", firstname, lastname);\nsystem.out.println(fullname);\n<\/pre>\n<p><strong>\u6f14\u793a\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>john doe\n<\/pre>\n<h3> 5.2 \u6027\u80fd\u8003\u8651 <\/h3>\n<p><strong>string.format()<\/strong> \u4e0d\u5982 <strong>stringbuilder<\/strong> \u6216 <strong>string.join()<\/strong> \u9ad8\u6548\uff0c\u4f46\u5b83\u5728\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u65f6\u63d0\u4f9b\u4e86\u7075\u6d3b\u6027\u3002 <\/p>\n<h3> 5.3 \u4f7f\u7528\u6848\u4f8b <\/h3>\n<ul>\n<li> <strong>\u52a8\u6001\u683c\u5f0f\u5316\uff1a<\/strong>\u5f53\u60a8\u9700\u8981\u4f7f\u7528\u5360\u4f4d\u7b26\u52a8\u6001\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u65f6\u3002<\/li>\n<li> <strong>\u53ef\u8bfb\u6027<\/strong>\uff1a\u5f53\u4ee3\u7801\u9700\u8981\u6613\u4e8e\u7406\u89e3\u65f6\u3002<\/li>\n<\/ul>\n<h3> 5.4 \u9650\u5236 <\/h3>\n<p><strong>\u6027\u80fd<\/strong> \uff1a\u6bd4 <strong>stringbuilder<\/strong> \u6216 <strong>string.join()<\/strong> \u7b49\u5176\u4ed6\u65b9\u6cd5\u6162\u3002 <\/p>\n<h2> \u516d\u3001\u7ed3\u8bba <\/h2>\n<p>\u5728 java \u4e2d\uff0c\u6709\u591a\u79cd\u8fde\u63a5\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\uff0c\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u81ea\u5df1\u7684\u4f18\u70b9\u548c\u7528\u4f8b\u3002 + \u8fd0\u7b97\u7b26\u7b80\u5355\u4e14\u53ef\u8bfb\uff0c\u4f46\u5bf9\u4e8e\u5927\u89c4\u6a21\u4e32\u8054\u53ef\u80fd\u6548\u7387\u4f4e\u4e0b\u3002 <strong>stringbuilder<\/strong> \u548c stringbuffer \u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\uff0c\u7279\u522b\u662f\u5728\u5faa\u73af\u6216\u591a\u7ebf\u7a0b\u73af\u5883\u4e2d\u3002 <strong>string.join()<\/strong> \u548c <strong>string.format()<\/strong> \u63d0\u4f9b\u4e86\u8fde\u63a5\u5b57\u7b26\u4e32\u7684\u4e13\u95e8\u65b9\u6cd5\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u5206\u9694\u7b26\u6216\u52a8\u6001\u683c\u5f0f\u65f6\u3002 <\/p>\n<p>\u9009\u62e9\u8fde\u63a5\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\u65f6\uff0c\u8bf7\u8003\u8651\u5e94\u7528\u7a0b\u5e8f\u7684\u7279\u5b9a\u9700\u6c42\uff0c\u4f8b\u5982\u6027\u80fd\u3001\u53ef\u8bfb\u6027\u548c\u7ebf\u7a0b\u5b89\u5168\u6027\u3002 <\/p>\n<p>\u5982\u679c\u60a8\u5bf9\u4e0a\u8ff0\u4efb\u4f55\u65b9\u6cd5\u6709\u4efb\u4f55\u7591\u95ee\u6216\u9700\u8981\u8fdb\u4e00\u6b65\u8bf4\u660e\uff0c\u8bf7\u968f\u65f6\u5728\u4e0b\u9762\u8bc4\u8bba\uff01 <\/p>\n<p><strong>\u9605\u8bfb\u66f4\u591a\u5e16\u5b50<\/strong>\uff1a\u5728 java \u4e2d\u8fde\u63a5\u5b57\u7b26\u4e32\u7684 5 \u4e2a\u7b80\u5355\u6280\u5de7<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java \u4e2d\u8fde\u63a5\u5b57\u7b26\u4e32\u7684 asy&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203753","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203753"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203753\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}