{"id":38027,"date":"2024-11-26T14:57:16","date_gmt":"2024-11-26T06:57:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38027\/"},"modified":"2024-11-26T14:57:16","modified_gmt":"2024-11-26T06:57:16","slug":"java%e6%80%8e%e4%b9%88%e5%88%9d%e5%a7%8b%e5%8c%96%e5%ad%97%e7%ac%a6%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38027\/","title":{"rendered":"java\u600e\u4e48\u521d\u59cb\u5316\u5b57\u7b26\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u521d\u59cb\u5316\u5b57\u7b26\u6570\u7ec4\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528\u5927\u62ec\u53f7 ({}) \u6307\u5b9a\u5b57\u7b26\u5143\u7d20\u3002\u4f7f\u7528 new \u8fd0\u7b97\u7b26\u521b\u5efa\u6570\u7ec4\u5e76\u6307\u5b9a\u5b57\u7b26\u5143\u7d20\uff0c\u4f7f\u7528 for \u5faa\u73af\u521d\u59cb\u5316\u5143\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111315394978784.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u521d\u59cb\u5316\u5b57\u7b26\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u521d\u59cb\u5316\u5b57\u7b26\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u521d\u59cb\u5316 Java \u5b57\u7b26\u6570\u7ec4<\/strong><\/p>\n<p>Java \u4e2d\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e24\u79cd\u65b9\u5f0f\u521d\u59cb\u5316\u5b57\u7b26\u6570\u7ec4\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u5927\u62ec\u53f7 ({})<\/strong><\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u76f4\u63a5\u5728\u6570\u7ec4\u58f0\u660e\u4e2d\u6307\u5b9a\u5b57\u7b26\u5143\u7d20\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>char[] chars = {'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r'};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 new \u8fd0\u7b97\u7b26<\/strong><\/p>\n<p>\u4f7f\u7528 new \u8fd0\u7b97\u7b26\u521b\u5efa\u6570\u7ec4\u5e76\u6307\u5b9a\u5b57\u7b26\u5143\u7d20\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>char[] chars = new char[n];\nfor (int i = 0; i &lt; n; i++) {\n    chars[i] = 'c';  \/\/ \u6216\u8005 chars[i] = your_character;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0cn \u662f\u8981\u521b\u5efa\u7684\u5b57\u7b26\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u5e76\u4e14\u4f7f\u7528 for \u5faa\u73af\u5c06\u6bcf\u4e2a\u5143\u7d20\u521d\u59cb\u5316\u4e3a\u5b57\u6bcd &#8216;c&#8217;\u3002<\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u5b57\u7b26\u6570\u7ec4\u5143\u7d20\u662f\u539f\u59cb\u7c7b\u578b char\uff0c\u800c\u4e0d\u662f\u5bf9\u8c61\u3002<\/li>\n<li>\u6570\u7ec4\u7684\u957f\u5ea6\u5728\u521b\u5efa\u540e\u4e0d\u80fd\u66f4\u6539\u3002<\/li>\n<li>\u521d\u59cb\u5316\u65f6\uff0c\u6570\u7ec4\u5143\u7d20\u5c06\u88ab\u81ea\u52a8\u521d\u59cb\u5316\u4e3a Unicode \u5b57\u7b26 &#8216;u0000&#8217;\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u521d\u59cb\u5316\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\u521d\u59cb\u5316\u5b57\u7b26\u6570\u7ec4\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528\u5927\u62ec\u53f7 ({}) \u6307\u5b9a\u5b57\u7b26\u5143\u7d20\u3002\u4f7f\u7528 new \u8fd0\u7b97\u7b26\u521b\u5efa\u6570\u7ec4\u5e76\u6307\u5b9a\u5b57\u7b26\u5143\u7d20\uff0c\u4f7f\u7528 for \u5faa\u73af\u521d\u59cb\u5316\u5143\u7d20\u3002 \u5982\u4f55\u521d\u59cb\u5316 Java \u5b57\u7b26\u6570\u7ec4 Java \u4e2d\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e24\u79cd\u65b9\u5f0f\u521d\u59cb\u5316\u5b57\u7b26\u6570\u7ec4\uff1a 1. \u4f7f\u7528\u5927\u62ec\u53f7 ({}) \u8fd9\u79cd\u65b9\u6cd5\u76f4\u63a5\u5728\u6570\u7ec4\u58f0\u660e\u4e2d\u6307\u5b9a\u5b57\u7b26\u5143\u7d20\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b char[] chars = {&#8216;c&#8217;, &#8216;h&#8217;, &#8216;a&#8217;, &#8216;r&#8217;, &#8216;a&#8217;, &#8216;c&#8217;, &#8216;t&#8217;, &#8216;e&#8217;, &#8216;r&#8217;}; \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 new \u8fd0\u7b97\u7b26 \u4f7f\u7528 new \u8fd0\u7b97\u7b26\u521b\u5efa\u6570\u7ec4\u5e76\u6307\u5b9a\u5b57\u7b26\u5143\u7d20\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a char[] chars = new char[n]; for (int i = 0; i &lt; n; i++) { chars[i] = [&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-38027","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38027","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=38027"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38027\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}