{"id":36989,"date":"2024-11-26T11:00:20","date_gmt":"2024-11-26T03:00:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36989\/"},"modified":"2024-11-26T11:00:20","modified_gmt":"2024-11-26T03:00:20","slug":"java-%e5%ad%97%e7%ac%a6%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%ae%9a%e4%b9%89-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36989\/","title":{"rendered":"java \u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49"},"content":{"rendered":"<blockquote><p>\n  java\u4e2d\u5b9a\u4e49\u5b57\u7b26\u6570\u7ec4\u7684\u8bed\u6cd5\u4e3a\uff1achar[] arrayname = new char[size]\u3002\u6570\u7ec4\u5927\u5c0f\u4e3asize\uff0c\u53ef\u5b58\u50a8unicode\u5b57\u7b26\uff0c\u901a\u8fc7\u4e0b\u6807\u53ef\u8bbf\u95ee\u5143\u7d20\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4f7f\u7528\u5b57\u7b26\u4e32\u521b\u5efa\u6570\u7ec4\u6216\u590d\u5236\u5df2\u6709\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111222545991802.jpg\" class=\"aligncenter\" title=\"java \u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49\u63d2\u56fe\" alt=\"java \u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u5b57\u7b26\u6570\u7ec4\u7684\u5b9a\u4e49<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 char[] \u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u6570\u7ec4\uff0c\u5b83\u53ef\u4ee5\u5b58\u50a8\u4e00\u7ec4 Unicode \u5b57\u7b26\u3002\u5176\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>char[] arrayName = new char[size];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>arrayName \u662f\u6570\u7ec4\u7684\u540d\u79f0\u3002<\/li>\n<li>size \u662f\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u8868\u793a\u6570\u7ec4\u53ef\u4ee5\u5b58\u50a8\u7684\u5b57\u7b26\u6570\u91cf\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>char[] myArray = new char[10];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5927\u5c0f\u4e3a 10 \u7684\u5b57\u7b26\u6570\u7ec4 myArray\u3002\u53ef\u4ee5\u4f7f\u7528\u4e0b\u6807\u4ece 0 \u5230 9 \u6765\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n<p><strong>\u5176\u4ed6\u65b9\u6cd5<\/strong><\/p>\n<p>\u9664\u4e86 new char[size] \u8bed\u6cd5\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5b9a\u4e49\u5b57\u7b26\u6570\u7ec4\uff1a<\/p>\n<ul>\n<li>\n<p><strong>\u4f7f\u7528\u5b57\u7b26\u4e32\u521b\u5efa\u6570\u7ec4\uff1a<\/strong><\/p>\n<pre>char[] myArray = \"Hello, world!\".toCharArray();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u5c06\u73b0\u6709\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\uff1a<\/strong><\/p>\n<pre>char[] myArray = {'H', 'e', 'l', 'l', 'o'};\nchar[] newArray = new char[myArray.length];\nSystem.arraycopy(myArray, 0, newArray, 0, myArray.length);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava \u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49\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\u5b9a\u4e49\u5b57\u7b26\u6570\u7ec4\u7684\u8bed\u6cd5\u4e3a\uff1achar[] arrayname = new char[size]\u3002\u6570\u7ec4\u5927\u5c0f\u4e3asize\uff0c\u53ef\u5b58\u50a8unicode\u5b57\u7b26\uff0c\u901a\u8fc7\u4e0b\u6807\u53ef\u8bbf\u95ee\u5143\u7d20\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4f7f\u7528\u5b57\u7b26\u4e32\u521b\u5efa\u6570\u7ec4\u6216\u590d\u5236\u5df2\u6709\u6570\u7ec4\u3002 Java \u5b57\u7b26\u6570\u7ec4\u7684\u5b9a\u4e49 \u5728 Java \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 char[] \u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u6570\u7ec4\uff0c\u5b83\u53ef\u4ee5\u5b58\u50a8\u4e00\u7ec4 Unicode \u5b57\u7b26\u3002\u5176\u8bed\u6cd5\u5982\u4e0b\uff1a char[] arrayName = new char[size]; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a arrayName \u662f\u6570\u7ec4\u7684\u540d\u79f0\u3002 size \u662f\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u8868\u793a\u6570\u7ec4\u53ef\u4ee5\u5b58\u50a8\u7684\u5b57\u7b26\u6570\u91cf\u3002 \u793a\u4f8b \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b char[] myArray = new char[10]; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5927\u5c0f\u4e3a 10 \u7684\u5b57\u7b26\u6570\u7ec4 myArray\u3002\u53ef\u4ee5\u4f7f\u7528\u4e0b\u6807\u4ece 0 \u5230 9 \u6765\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3002 \u5176\u4ed6\u65b9\u6cd5 \u9664\u4e86 new char[size] \u8bed\u6cd5\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5b9a\u4e49\u5b57\u7b26\u6570\u7ec4\uff1a \u4f7f\u7528\u5b57\u7b26\u4e32\u521b\u5efa\u6570\u7ec4\uff1a char[] myArray = &#8220;Hello, world!&#8221;.toCharArray(); \u767b\u5f55\u540e\u590d\u5236 \u5c06\u73b0\u6709\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\uff1a char[] [&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-36989","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36989","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=36989"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36989\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}