{"id":338,"date":"2023-09-16T10:32:08","date_gmt":"2023-09-16T02:32:08","guid":{"rendered":""},"modified":"2023-09-18T11:49:45","modified_gmt":"2023-09-18T03:49:45","slug":"string%e6%95%b0%e7%bb%84%e5%88%9d%e5%a7%8b%e5%8c%96","status":"publish","type":"post","link":"https:\/\/mushiming.com\/338.html","title":{"rendered":"String[]\u6570\u7ec4\u521d\u59cb\u5316"},"content":{"rendered":"

\u521b\u5efa\u6570\u7ec4\uff1a<\/h1>\n
\n \/\/\u4e00\u7ef4\u6570\u7ec4<\/span>
\n

\n String[] str = new String[5]; \/\/\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a5\u7684String(\u5b57\u7b26\u4e32)\u578b\u7684\u4e00\u7ef4\u6570\u7ec4<\/span>
\n

\n String[] str = new String[]{\"\",\"\",\"\",\"\",\"\"};<\/span>
\n

\n String[] str = {\"\",\"\",\"\",\"\",\"\"};<\/span>
\n

\n \/\/\u4e8c\u7ef4\u6570\u7ec4<\/span>
\n

\n String[][] str = new String[2][2]; \/\/\u521b\u5efa\u4e00\u4e2a2\u884c2\u5217\u7684\u4e8c\u7ef4\u6570\u7ec4<\/span>
\n
\n<\/div>\n
\n
<\/span>\n<\/div>\n

String\u6570\u7ec4\u521d\u59cb\u5316\u533a\u522b:<\/span><\/span><\/span><\/h1>\n
\n String[] str = {\"1\",\"2\",\"3\"}\u4e0eString[] str = new String[]{\"1\",\"2\",\"3\"}\u5728\u5185\u5b58\u91cc\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/span>
\u3000\u3000\u7f16\u8bd1\u6267\u884c\u7ed3\u679c\u6ca1\u6709\u4efb\u4f55\u533a\u522b\u3002\u66f4\u4e0d\u53ef\u80fd\u50cf\u6709\u4e9b\u4eba\u60f3\u5f53\u7136\u8bf4\u7684\u5728\u6808\u4e0a\u5206\u914d\u7a7a\u95f4\uff0cJava\u7684\u5bf9\u8c61\u90fd\u662f\u5728\u5806\u4e0a\u5206\u914d\u7a7a\u95f4\u7684\u3002<\/span>
\u3000\u3000\u8fd9\u91cc\u7684\u533a\u522b\u4ec5\u4ec5\u662f\u4ee3\u7801\u4e66\u5199\u4e0a\u7684\uff1a\u3000<\/span>
String[] str = <\/span>{\"1\",\"2\",\"3\"}; \u8fd9\u79cd\u5f62\u5f0f\u53eb\u6570\u7ec4\u521d\u59cb\u5316\u5f0f\uff08Array Initializer\uff09\uff0c\u53ea\u80fd\u7528\u5728\u58f0\u660e\u540c\u65f6\u8d4b\u503c\u7684\u60c5\u51b5\u4e0b\u3002<\/span>
\u3000\u3000\u800c String[] str = new String[]{\"1\",\"2\",\"3\"} \u662f\u4e00\u822c\u5f62\u5f0f\u7684\u8d4b\u503c\uff0c=\u53f7\u7684\u53f3\u8fb9\u53eb\u6570\u7ec4\u5b57\u9762\u91cf\uff08Array Literal\uff09\uff0c\u6570\u7ec4\u5b57\u9762\u91cf\u53ef\u4ee5\u7528\u5728\u4efb\u4f55\u9700\u8981\u4e00\u4e2a\u6570\u7ec4\u7684\u5730\u65b9\uff08\u7c7b\u578b\u517c\u5bb9\u7684\u60c5\u51b5\u4e0b\uff09\u3002\u5982\uff1a<\/span>
\u3000\u3000String[] str = {\"1\",\"2\",\"3\"}; \/\/ \u6b63\u786e\u7684<\/span>
\u3000\u3000String[] str = new String[]{\"1\",\"2\",\"3\"} \/\/ \u4e5f\u662f\u6b63\u786e\u7684<\/span>
\u800c<\/span>
\u3000\u3000String[] str;<\/span>
\u3000\u3000str = {\"1\",\"2\",\"3\"}; \/\/ \u7f16\u8bd1\u9519\u8bef<\/span>
\u56e0\u4e3a\u6570\u7ec4\u521d\u59cb\u5316\u5f0f\u53ea\u80fd\u7528\u4e8e\u58f0\u660e\u540c\u65f6\u8d4b\u503c\u7684\u60c5\u51b5\u4e0b\u3002<\/span>

\u6539\u4e3a\uff1a<\/span>
\u3000\u3000String[] str;<\/span>
\u3000\u3000str = new String[] {\"1\",\"2\",\"3\"}; \/\/ \u6b63\u786e\u4e86<\/span>
\u53c8\u5982\uff1a<\/span>
\u3000\u3000void f(String[] str) {
\n <\/span>
\u3000\u3000}<\/span>
\u3000\u3000f({\"1\",\"2\",\"3\"}); \/\/ \u7f16\u8bd1\u9519\u8bef<\/span>
\u6b63\u786e\u7684\u5e94\u8be5\u662f\uff1a<\/span>
\u3000\u3000f(new String[] {\"1\",\"2\",\"3\"});<\/span>
<\/span><\/span><\/span>\n<\/div>\n
\n
<\/span><\/span><\/span><\/span>\n<\/div>\n
\n \u6ce8\u610f\uff1a\u521d\u59cb\u5316\u6570\u7ec4\u7684\u65f6\u5019\u5b9a\u4e49\u4e3aString[] str = new String[]{}\uff0c\u5982\u6b64\u5b9a\u4e49\u76f8\u5f53\u4e8e\u521b\u5efa\u4e86\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a0\u7684String(\u5b57\u7b26\u4e32)\u578b\u7684\u4e00\u7ef4\u6570\u7ec4\u3002\u5728\u540e\u671f\u4e3a\u5176\u8d4b\u503c\u7684\u65f6\u5019str[0]=\"A\"\uff0c\u5c31\u4f1a\u629b\u51fa\u5f02\u5e38\u3002<\/span><\/span><\/span>\n<\/div>\n","protected":false},"excerpt":{"rendered":"String[]\u6570\u7ec4\u521d\u59cb\u5316\u521b\u5efa\u6570\u7ec4\uff1a\/\/\u4e00\u7ef4\u6570\u7ec4String[]str=newString[5];\/\/\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a5\u7684String(\u5b57\u7b26\u4e32)\u578b\u7684\u4e00\u7ef4\u6570\u7ec4String[]s...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/338"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=338"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/338\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}