{"id":40224,"date":"2024-11-26T11:28:49","date_gmt":"2024-11-26T03:28:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/40224\/"},"modified":"2024-11-26T11:28:49","modified_gmt":"2024-11-26T03:28:49","slug":"java%e6%80%8e%e4%b9%88%e6%8a%8a%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%ad%98%e5%88%b0%e5%ad%97%e7%ac%a6%e6%95%b0%e7%bb%84%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/40224\/","title":{"rendered":"java\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u5b58\u5230\u5b57\u7b26\u6570\u7ec4\u4e2d"},"content":{"rendered":"<blockquote><p>\n  \u65b9\u6cd5\uff1a\u76f4\u63a5\u8d4b\u503c\uff1astring str = &#8220;hello world&#8221;; char[] chars = str.tochararray();system.arraycopy()\uff1astring str = &#8220;hello world&#8221;; char[] chars = new char[str.length()]; system.arraycopy(str.tochararray(), 0, chars, 0, str.length());stringbuilder \u8f6c\u6362\uff1astring str = &#8220;h\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111723311754808.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u5b58\u5230\u5b57\u7b26\u6570\u7ec4\u4e2d\u63d2\u56fe\" alt=\"java\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u5b58\u5230\u5b57\u7b26\u6570\u7ec4\u4e2d\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u5c06\u5b57\u7b26\u4e32\u5b58\u50a8\u5230\u5b57\u7b26\u6570\u7ec4\u7684\u65b9\u6cd5<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u8d4b\u503c<\/strong><\/p>\n<pre>String str = \"Hello World\";\nchar[] chars = str.toCharArray();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 System.arraycopy()<\/strong><\/p>\n<pre>String str = \"Hello World\";\nchar[] chars = new char[str.length()];\nSystem.arraycopy(str.toCharArray(), 0, chars, 0, str.length());<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 StringBuilder \u8f6c\u6362<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String str = \"Hello World\";\nStringBuilder sb = new StringBuilder(str);\nchar[] chars = new char[sb.length()];\nsb.getChars(0, sb.length(), chars, 0);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8be6\u7ec6\u4ecb\u7ecd<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u8d4b\u503c<\/strong><\/p>\n<p>toCharArray() \u65b9\u6cd5\u76f4\u63a5\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5b57\u7b26\u7684\u5b57\u7b26\u6570\u7ec4\u3002\u8fd9\u79cd\u65b9\u6cd5\u6548\u7387\u6700\u9ad8\uff0c\u4f46\u4ec5\u9002\u7528\u4e8e\u4e0d\u53ef\u53d8\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>\u4f7f\u7528 System.arraycopy()<\/strong><\/p>\n<p>System.arraycopy() \u65b9\u6cd5\u5c06\u4e00\u4e2a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u590d\u5236\u5230\u53e6\u4e00\u4e2a\u6570\u7ec4\u3002\u4f7f\u7528\u6b64\u65b9\u6cd5\u65f6\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u5b57\u7b26\u6570\u7ec4\u5e76\u6307\u5b9a\u5176\u957f\u5ea6\uff0c\u7136\u540e\u624d\u80fd\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002<\/p>\n<p><strong>\u4f7f\u7528 StringBuilder \u8f6c\u6362<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>StringBuilder \u7c7b\u662f\u4e00\u4e2a\u53ef\u53d8\u5b57\u7b26\u5e8f\u5217\uff0c\u5b83\u5141\u8bb8\u9ad8\u6548\u5730\u4fee\u6539\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 getChars() \u65b9\u6cd5\u53ef\u4ee5\u5c06 StringBuilder \u5bf9\u8c61\u4e2d\u7684\u5b57\u7b26\u590d\u5236\u5230\u4e00\u4e2a\u5b57\u7b26\u6570\u7ec4\u4e2d\u3002<\/p>\n<p><strong>\u9009\u62e9\u65b9\u6cd5<\/strong><\/p>\n<p>\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u4ee5\u4e0b\u56e0\u7d20\uff1a<\/p>\n<ul>\n<li> <strong>\u5b57\u7b26\u4e32\u7684\u53ef\u53d8\u6027\uff1a<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e0d\u53ef\u53d8\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u76f4\u63a5\u8d4b\u503c\u65b9\u6cd5\u3002<\/li>\n<li> <strong>\u6548\u7387\uff1a<\/strong>\u76f4\u63a5\u8d4b\u503c\u65b9\u6cd5\u6548\u7387\u6700\u9ad8\uff0c\u5176\u6b21\u662f StringBuilder \u8f6c\u6362\u65b9\u6cd5\uff0c\u6700\u540e\u662f System.arraycopy() \u65b9\u6cd5\u3002<\/li>\n<li> <strong>\u65b0\u6570\u7ec4\u7684\u521b\u5efa\uff1a<\/strong>System.arraycopy() \u548c StringBuilder \u8f6c\u6362\u65b9\u6cd5\u9700\u8981\u521b\u5efa\u65b0\u7684\u5b57\u7b26\u6570\u7ec4\uff0c\u800c\u76f4\u63a5\u8d4b\u503c\u65b9\u6cd5\u4e0d\u9700\u8981\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u5b58\u5230\u5b57\u7b26\u6570\u7ec4\u4e2d\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65b9\u6cd5\uff1a\u76f4\u63a5\u8d4b\u503c\uff1astring str = &#8220;hello world&#8221;; char[] chars = str.tochararray();system.arraycopy()\uff1astring str = &#8220;hello world&#8221;; char[] chars = new char[str.length()]; system.arraycopy(str.tochararray(), 0, chars, 0, str.length());stringbuilder \u8f6c\u6362\uff1astring str = &#8220;h Java \u4e2d\u5c06\u5b57\u7b26\u4e32\u5b58\u50a8\u5230\u5b57\u7b26\u6570\u7ec4\u7684\u65b9\u6cd5 \u76f4\u63a5\u8d4b\u503c String str = &#8220;Hello World&#8221;; char[] chars = str.toCharArray(); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 System.arraycopy() String str = &#8220;Hello World&#8221;; char[] chars = new char[str.length()]; System.arraycopy(str.toCharArray(), 0, chars, [&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-40224","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40224","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=40224"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40224\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=40224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=40224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=40224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}