{"id":34595,"date":"2024-11-26T10:20:40","date_gmt":"2024-11-26T02:20:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34595\/"},"modified":"2024-11-26T10:20:40","modified_gmt":"2024-11-26T02:20:40","slug":"java%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%80%8e%e4%b9%88%e8%bd%ac%e4%b8%ba%e5%ad%97%e7%ac%a6%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34595\/","title":{"rendered":"JAVA\u5b57\u7b26\u4e32\u600e\u4e48\u8f6c\u4e3a\u5b57\u7b26\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  java\u4e2d\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 tochararray() \u65b9\u6cd5\u3002\u4f7f\u7528 getchars() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u590d\u5236\u5230\u5b57\u7b26\u6570\u7ec4\u4e2d\u3002\u4f7f\u7528 getbytes() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002\u4f7f\u7528 string.valueof() \u65b9\u6cd5\u5c06\u5176\u4ed6\u7c7b\u578b\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/02\/2024110217333088837.jpg\" class=\"aligncenter\" title=\"JAVA\u5b57\u7b26\u4e32\u600e\u4e48\u8f6c\u4e3a\u5b57\u7b26\u6570\u7ec4\u63d2\u56fe\" alt=\"JAVA\u5b57\u7b26\u4e32\u600e\u4e48\u8f6c\u4e3a\u5b57\u7b26\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>Java\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4<\/strong><\/p>\n<p>Java\u4e2d\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7toCharArray()\u65b9\u6cd5\u5b9e\u73b0\u3002\u8be5\u65b9\u6cd5\u8fd4\u56de\u5b57\u7b26\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u5bf9\u5e94\u5b57\u7b26\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>char[] toCharArray()<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String str = \"Hello World\";\nchar[] chars = str.toCharArray();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0ctoCharArray()\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32&#8221;Hello World&#8221;\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4chars\u3002\u8be5\u6570\u7ec4\u5305\u542b11\u4e2a\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\uff1a<\/p>\n<pre>chars[0] == 'H'\nchars[1] == 'e'\nchars[2] == 'l'\nchars[3] == 'l'\nchars[4] == 'o'\nchars[5] == ' '\nchars[6] == 'W'\nchars[7] == 'o'\nchars[8] == 'r'\nchars[9] == 'l'\nchars[10] == 'd'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4ed6\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u9664\u4e86toCharArray()\u65b9\u6cd5\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\uff1a<\/p>\n<ul>\n<li> <strong>getChars()\u65b9\u6cd5\uff1a<\/strong>\u8be5\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u590d\u5236\u5230\u6307\u5b9a\u7684\u5b57\u7b26\u6570\u7ec4\u4e2d\u3002<\/li>\n<li> <strong>getBytes()\u65b9\u6cd5\uff1a<\/strong>\u8be5\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\uff0c\u7136\u540e\u53ef\u4ee5\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002<\/li>\n<li> <strong>\u4f7f\u7528String.valueOf()\u65b9\u6cd5\uff1a<\/strong>\u8be5\u65b9\u6cd5\u5c06\u5176\u4ed6\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff08\u5982int\u3001long\uff09\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u53ef\u4ee5\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u5b57\u7b26\u6570\u7ec4\u4e2d\u7684\u5b57\u7b26\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u8fd9\u610f\u5473\u7740\u65e0\u6cd5\u4fee\u6539\u5b83\u4eec\u3002<\/li>\n<li>\u5982\u679c \u5b57\u7b26\u4e32\u5305\u542bUnicode\u5b57\u7b26\uff0c\u5219 toCharArray()\u65b9\u6cd5\u5c06\u8fd4\u56de\u4e00\u4e2aUnicode\u5b57\u7b26\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fJAVA\u5b57\u7b26\u4e32\u600e\u4e48\u8f6c\u4e3a\u5b57\u7b26\u6570\u7ec4\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>java\u4e2d\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 tochararray() \u65b9\u6cd5\u3002\u4f7f\u7528 getchars() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u590d\u5236\u5230\u5b57\u7b26\u6570\u7ec4\u4e2d\u3002\u4f7f\u7528 getbytes() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002\u4f7f\u7528 string.valueof() \u65b9\u6cd5\u5c06\u5176\u4ed6\u7c7b\u578b\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002 Java\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4 Java\u4e2d\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7toCharArray()\u65b9\u6cd5\u5b9e\u73b0\u3002\u8be5\u65b9\u6cd5\u8fd4\u56de\u5b57\u7b26\u6570\u7ec4\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u5bf9\u5e94\u5b57\u7b26\u3002 \u8bed\u6cd5\uff1a char[] toCharArray() \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b String str = &#8220;Hello World&#8221;; char[] chars = str.toCharArray(); \u767b\u5f55\u540e\u590d\u5236 \u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0ctoCharArray()\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32&#8221;Hello World&#8221;\u8f6c\u6362\u4e3a\u5b57\u7b26\u6570\u7ec4chars\u3002\u8be5\u6570\u7ec4\u5305\u542b11\u4e2a\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\uff1a chars[0] == &#8216;H&#8217; chars[1] == &#8216;e&#8217; chars[2] == &#8216;l&#8217; chars[3] == &#8216;l&#8217; chars[4] == &#8216;o&#8217; chars[5] == &#8216; &#8216; chars[6] == &#8216;W&#8217; chars[7] == &#8216;o&#8217; chars[8] [&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-34595","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34595","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=34595"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34595\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}