{"id":66642,"date":"2025-05-03T09:36:32","date_gmt":"2025-05-03T01:36:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66642\/"},"modified":"2025-05-03T09:36:32","modified_gmt":"2025-05-03T01:36:32","slug":"java%e4%b8%adchar%e6%95%b0%e7%bb%84%e7%9a%84%e5%80%bc%e6%80%8e%e4%b9%88%e8%a1%a8%e7%a4%ba-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66642\/","title":{"rendered":"java\u4e2dchar\u6570\u7ec4\u7684\u503c\u600e\u4e48\u8868\u793a"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d char \u6570\u7ec4\u7684\u503c\u8868\u793a unicode \u5b57\u7b26\uff0c\u6bcf\u4e2a\u5143\u7d20\u5b58\u50a8\u4e00\u4e2a 16 \u4f4d\u4ee3\u7801\u5355\u5143\u3002char \u6570\u7ec4\u53ef\u4ee5\u8868\u793a\u57fa\u672c\u591a\u8bed\u8a00\u5e73\u9762 (bmp) \u548c\u8f85\u52a9\u5e73\u9762\u4e2d\u7684\u5b57\u7b26\uff0c\u8303\u56f4\u4ece 0x0000 \u5230 0x10ffff\u3002\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u6765\u8bbf\u95ee char \u6570\u7ec4\u7684\u503c\uff0c\u4e5f\u53ef\u4ee5\u5c06 char \u6570\u7ec4\u8f6c\u6362\u4e3a string \u6216\u4ece string \u8f6c\u6362\u4e3a char \u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111611340787181.jpg\" class=\"aligncenter\" title=\"java\u4e2dchar\u6570\u7ec4\u7684\u503c\u600e\u4e48\u8868\u793a\u63d2\u56fe\" alt=\"java\u4e2dchar\u6570\u7ec4\u7684\u503c\u600e\u4e48\u8868\u793a\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d char \u6570\u7ec4\u7684\u503c\u8868\u793a<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0cchar \u6570\u7ec4\u4e2d\u7684\u503c\u4f7f\u7528 Unicode \u5b57\u7b26\u7f16\u7801\u8868\u793a\u3002Unicode \u662f\u4e00\u4e2a\u56fd\u9645\u6807\u51c6\uff0c\u5b9a\u4e49\u4e86\u51e0\u4e4e\u6240\u6709\u4e66\u9762\u8bed\u8a00\u4e2d\u4f7f\u7528\u7684\u6240\u6709\u5b57\u7b26\u3002\u6bcf\u4e2a Unicode \u5b57\u7b26\u90fd\u5206\u914d\u4e86\u4e00\u4e2a\u552f\u4e00\u7684\u4ee3\u7801\u70b9\uff0c\u8be5\u4ee3\u7801\u70b9\u7531\u4e00\u4e2a\u6216\u591a\u4e2a 16 \u4f4d\u4ee3\u7801\u5355\u5143\u8868\u793a\u3002<\/p>\n<p><strong>char \u6570\u7ec4\u4e2d\u7684\u503c\u5b58\u50a8\u65b9\u5f0f<\/strong><\/p>\n<p>\u6bcf\u4e2a char \u6570\u7ec4\u5143\u7d20\u5b58\u50a8\u4e00\u4e2a 16 \u4f4d Unicode \u4ee3\u7801\u5355\u5143\u3002\u8fd9\u610f\u5473\u7740 char \u6570\u7ec4\u53ef\u4ee5\u8868\u793a 2^16 = 65,536 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u8868\u793a\u5b57\u7b26\u7684\u8303\u56f4<\/strong><\/p>\n<p>Java \u4e2d char \u6570\u7ec4\u7684\u503c\u8868\u793a Unicode \u5b57\u7b26\u7684\u4ee5\u4e0b\u8303\u56f4\uff1a<\/p>\n<ul>\n<li> <strong>\u57fa\u672c\u591a\u8bed\u8a00\u5e73\u9762 (BMP)<\/strong>\uff1a\u4ee3\u7801\u70b9\u4ece 0x0000 \u5230 0xFFFF\u3002\u6b64\u8303\u56f4\u5305\u62ec\u5927\u591a\u6570\u5e38\u7528\u5b57\u7b26\uff0c\u4f8b\u5982\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u6807\u70b9\u7b26\u53f7\u3002<\/li>\n<li> <strong>\u8f85\u52a9\u5e73\u9762<\/strong>\uff1a\u4ee3\u7801\u70b9\u4ece 0x10000 \u5230 0x10FFFF\u3002\u6b64\u8303\u56f4\u5305\u62ec\u8f83\u4e0d\u5e38\u7528\u7684\u5b57\u7b26\uff0c\u4f8b\u5982\u8868\u60c5\u7b26\u53f7\u3001\u8c61\u5f62\u6587\u5b57\u548c\u4e50\u8c31\u7b26\u53f7\u3002<\/li>\n<\/ul>\n<p><strong>\u8bbf\u95ee char \u6570\u7ec4\u4e2d\u7684\u503c<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7\u7d22\u5f15\u6765\u8bbf\u95ee char \u6570\u7ec4\u4e2d\u7684\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>char[] chars = {'H', 'e', 'l', 'l', 'o'};\nchar firstCharacter = chars[0]; \/\/ 'H'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f6c\u6362 char \u6570\u7ec4\u4e3a String<\/strong><\/p>\n<p>\u53ef\u4ee5\u5c06 char \u6570\u7ec4\u8f6c\u6362\u4e3a String\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>String str = new String(chars); \/\/ \"Hello\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f6c\u6362 String \u4e3a char \u6570\u7ec4<\/strong><\/p>\n<p>\u4e5f\u53ef\u4ee5\u5c06 String \u8f6c\u6362\u4e3a char \u6570\u7ec4\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>char[] chars = str.toCharArray();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e2dchar\u6570\u7ec4\u7684\u503c\u600e\u4e48\u8868\u793a\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java \u4e2d char \u6570\u7ec4\u7684\u503c\u8868\u793a unicode \u5b57\u7b26\uff0c\u6bcf\u4e2a\u5143\u7d20\u5b58\u50a8\u4e00\u4e2a 16 \u4f4d\u4ee3\u7801\u5355\u5143\u3002char \u6570\u7ec4\u53ef\u4ee5\u8868\u793a\u57fa\u672c\u591a\u8bed\u8a00\u5e73\u9762 (bmp) \u548c\u8f85\u52a9\u5e73\u9762\u4e2d\u7684\u5b57\u7b26\uff0c\u8303\u56f4\u4ece 0x0000 \u5230 0x10ffff\u3002\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u6765\u8bbf\u95ee char \u6570\u7ec4\u7684\u503c\uff0c\u4e5f\u53ef\u4ee5\u5c06 char \u6570\u7ec4\u8f6c\u6362\u4e3a string \u6216\u4ece string \u8f6c\u6362\u4e3a char \u6570\u7ec4\u3002 Java \u4e2d char \u6570\u7ec4\u7684\u503c\u8868\u793a \u5728 Java \u4e2d\uff0cchar \u6570\u7ec4\u4e2d\u7684\u503c\u4f7f\u7528 Unicode \u5b57\u7b26\u7f16\u7801\u8868\u793a\u3002Unicode \u662f\u4e00\u4e2a\u56fd\u9645\u6807\u51c6\uff0c\u5b9a\u4e49\u4e86\u51e0\u4e4e\u6240\u6709\u4e66\u9762\u8bed\u8a00\u4e2d\u4f7f\u7528\u7684\u6240\u6709\u5b57\u7b26\u3002\u6bcf\u4e2a Unicode \u5b57\u7b26\u90fd\u5206\u914d\u4e86\u4e00\u4e2a\u552f\u4e00\u7684\u4ee3\u7801\u70b9\uff0c\u8be5\u4ee3\u7801\u70b9\u7531\u4e00\u4e2a\u6216\u591a\u4e2a 16 \u4f4d\u4ee3\u7801\u5355\u5143\u8868\u793a\u3002 char \u6570\u7ec4\u4e2d\u7684\u503c\u5b58\u50a8\u65b9\u5f0f \u6bcf\u4e2a char \u6570\u7ec4\u5143\u7d20\u5b58\u50a8\u4e00\u4e2a 16 \u4f4d Unicode \u4ee3\u7801\u5355\u5143\u3002\u8fd9\u610f\u5473\u7740 char \u6570\u7ec4\u53ef\u4ee5\u8868\u793a 2^16 = 65,536 \u4e2a\u4e0d\u540c\u7684\u5b57\u7b26\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b [&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-66642","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66642","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=66642"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66642\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}