{"id":37011,"date":"2024-11-26T08:56:04","date_gmt":"2024-11-26T00:56:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/37011\/"},"modified":"2024-11-26T08:56:04","modified_gmt":"2024-11-26T00:56:04","slug":"java%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e6%94%be%e6%b1%89%e5%ad%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/37011\/","title":{"rendered":"java\u6570\u7ec4\u600e\u4e48\u653e\u6c49\u5b57"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u6570\u7ec4\u4e2d\u5b58\u50a8\u6c49\u5b57\u7684\u65b9\u6cd5\u6709\uff1a\u76f4\u63a5\u5b58\u50a8\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 char \u6570\u7ec4\u3002\u4f7f\u7528 byte \u6570\u7ec4\u3002\u4f7f\u7528 utf-8 \u7f16\u7801\u7684 string \u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111223242729482.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u600e\u4e48\u653e\u6c49\u5b57\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u600e\u4e48\u653e\u6c49\u5b57\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Java \u6570\u7ec4\u4e2d\u5b58\u50a8\u6c49\u5b57<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u5b58\u50a8\u5b57\u7b26\u4e32\uff1a<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5c06\u6c49\u5b57\u5b57\u7b26\u76f4\u63a5\u5b58\u50a8\u5728\u4e2d\u3002Java \u4e2d\u7684\u5b57\u7b26\u4e32\u662f Unicode \u7f16\u7801\u7684\uff0c\u56e0\u6b64\u652f\u6301\u6c49\u5b57\u3002<\/p>\n<pre>String[] \u6c49\u5b57\u6570\u7ec4 = {\"\u5317\u4eac\", \"\u4e0a\u6d77\", \"\u5e7f\u5dde\", \"\u6df1\u5733\"};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 char \u6570\u7ec4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u5982\u679c\u6570\u636e\u91cf\u8f83\u5927\uff0c\u53ef\u4ee5\u4f7f\u7528 char \u6570\u7ec4\u6765\u5b58\u50a8\u6c49\u5b57\uff0c\u56e0\u4e3a\u5b83\u6bd4 String \u6570\u7ec4\u5360\u7528\u66f4\u5c11\u7684\u5185\u5b58\u3002\u6bcf\u4e2a char \u5143\u7d20\u53ef\u4ee5\u5b58\u50a8\u4e00\u4e2a Unicode \u5b57\u7b26\uff0c\u5305\u62ec\u6c49\u5b57\u3002<\/p>\n<pre>char[] \u6c49\u5b57\u6570\u7ec4 = {'\u5317', '\u4eac', '\u4e0a', '\u6d77', '\u5e7f', '\u5dde', '\u6df1', '\u5733'};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 byte \u6570\u7ec4\uff1a<\/strong><\/p>\n<p>\u5bf9\u4e8e\u9700\u8981\u6700\u5927\u9650\u5ea6\u63d0\u9ad8\u5185\u5b58\u5229\u7528\u7387\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528 byte \u6570\u7ec4\u6765\u5b58\u50a8\u6c49\u5b57\u3002\u6c49\u5b57\u5b57\u7b26\u7531 UTF-8 \u7f16\u7801\u8868\u793a\uff0c\u901a\u5e38\u9700\u8981 3 \u4e2a\u5b57\u8282\u3002<\/p>\n<pre>byte[] \u6c49\u5b57\u6570\u7ec4 = \"\u5317\u4eac\".getBytes(\"UTF-8\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 UTF-8 \u7f16\u7801\u7684 String \u6570\u7ec4\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u5904\u7406\u591a\u5b57\u8282\u6c49\u5b57\u5b57\u7b26\uff0c\u53ef\u4ee5\u4f7f\u7528 UTF-8 \u7f16\u7801\u7684 String \u6570\u7ec4\u3002String \u7c7b\u63d0\u4f9b\u4e86 getBytes() \u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u7f16\u7801\u4e3a\u5b57\u8282\u6570\u7ec4\uff0c\u518d\u5c06\u5176\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002<\/p>\n<pre>String[] \u6c49\u5b57\u6570\u7ec4 = {\"\u5317\u4eac\", \"\u4e0a\u6d77\", \"\u5e7f\u5dde\", \"\u6df1\u5733\"};\nbyte[][] \u6c49\u5b57\u5b57\u8282\u6570\u7ec4 = new byte[\u6c49\u5b57\u6570\u7ec4.length][];\nfor (int i = 0; i &lt; \u6c49\u5b57\u6570\u7ec4.length; i++) {\n    \u6c49\u5b57\u5b57\u8282\u6570\u7ec4[i] = \u6c49\u5b57\u6570\u7ec4[i].getBytes(\"UTF-8\");\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u6c49\u5b57\u5360\u7528\u591a\u4e2a\u5b57\u8282\u7a7a\u95f4\uff0c\u56e0\u6b64\u6570\u7ec4\u5143\u7d20\u9700\u8981\u5206\u914d\u8db3\u591f\u7684\u5185\u5b58\u3002<\/li>\n<li>\u5bf9\u4e8e\u8f83\u957f\u7684\u6c49\u5b57\u5b57\u7b26\u4e32\uff0c\u5efa\u8bae\u4f7f\u7528 String \u6570\u7ec4\u6216 UTF-8 \u7f16\u7801\u7684 String \u6570\u7ec4\u3002<\/li>\n<li>\u4e0d\u540c\u7684\u7f16\u7801\u65b9\u5f0f\u4f1a\u5bfc\u81f4\u5b57\u8282\u6570\u7ec4\u7684\u5927\u5c0f\u548c\u5185\u5bb9\u4e0d\u540c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u600e\u4e48\u653e\u6c49\u5b57\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>\u5728 java \u6570\u7ec4\u4e2d\u5b58\u50a8\u6c49\u5b57\u7684\u65b9\u6cd5\u6709\uff1a\u76f4\u63a5\u5b58\u50a8\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 char \u6570\u7ec4\u3002\u4f7f\u7528 byte \u6570\u7ec4\u3002\u4f7f\u7528 utf-8 \u7f16\u7801\u7684 string \u6570\u7ec4\u3002 \u5982\u4f55\u5728 Java \u6570\u7ec4\u4e2d\u5b58\u50a8\u6c49\u5b57 \u76f4\u63a5\u5b58\u50a8\u5b57\u7b26\u4e32\uff1a \u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5c06\u6c49\u5b57\u5b57\u7b26\u76f4\u63a5\u5b58\u50a8\u5728\u4e2d\u3002Java \u4e2d\u7684\u5b57\u7b26\u4e32\u662f Unicode \u7f16\u7801\u7684\uff0c\u56e0\u6b64\u652f\u6301\u6c49\u5b57\u3002 String[] \u6c49\u5b57\u6570\u7ec4 = {&#8220;\u5317\u4eac&#8221;, &#8220;\u4e0a\u6d77&#8221;, &#8220;\u5e7f\u5dde&#8221;, &#8220;\u6df1\u5733&#8221;}; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 char \u6570\u7ec4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5982\u679c\u6570\u636e\u91cf\u8f83\u5927\uff0c\u53ef\u4ee5\u4f7f\u7528 char \u6570\u7ec4\u6765\u5b58\u50a8\u6c49\u5b57\uff0c\u56e0\u4e3a\u5b83\u6bd4 String \u6570\u7ec4\u5360\u7528\u66f4\u5c11\u7684\u5185\u5b58\u3002\u6bcf\u4e2a char \u5143\u7d20\u53ef\u4ee5\u5b58\u50a8\u4e00\u4e2a Unicode \u5b57\u7b26\uff0c\u5305\u62ec\u6c49\u5b57\u3002 char[] \u6c49\u5b57\u6570\u7ec4 = {&#8216;\u5317&#8217;, &#8216;\u4eac&#8217;, &#8216;\u4e0a&#8217;, &#8216;\u6d77&#8217;, &#8216;\u5e7f&#8217;, &#8216;\u5dde&#8217;, &#8216;\u6df1&#8217;, &#8216;\u5733&#8217;}; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 byte \u6570\u7ec4\uff1a [&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-37011","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37011","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=37011"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37011\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=37011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=37011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=37011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}