{"id":328,"date":"2023-09-16T10:32:10","date_gmt":"2023-09-16T02:32:10","guid":{"rendered":""},"modified":"2023-09-18T11:50:03","modified_gmt":"2023-09-18T03:50:03","slug":"java%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e5%88%9d%e5%a7%8b%e5%8c%96%e5%92%8c%e8%b5%8b%e5%80%bc","status":"publish","type":"post","link":"https:\/\/mushiming.com\/328.html","title":{"rendered":"java\u5b57\u7b26\u4e32\u6570\u7ec4\u521d\u59cb\u5316\u548c\u8d4b\u503c"},"content":{"rendered":"

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

String\u6570\u7ec4\u521d\u59cb\u5316\u533a\u522b<\/strong><\/span><\/p>\n

       \u9996\u5148\u5e94\u8be5\u660e\u767djava\u6570\u7ec4\u91cc\u9762\u5b58\u7684\u662f\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u6240\u4ee5\u5fc5\u987b\u521d\u59cb\u5316\u624d\u80fd\u7528\uff1b <\/p>\n

\u3000\u3000String[] str = {\"1\",\"2\",\"3\"}\u4e0eString[] str = newString[]{\"1\",\"2\",\"3\"}\u5728\u5185\u5b58\u91cc\u6709\u4ec0\u4e48\u533a\u522b\uff1f
\n
\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 <\/p>\n

\u3000\u3000\u8fd9\u91cc\u7684\u533a\u522b\u4ec5\u4ec5\u662f\u4ee3\u7801\u4e66\u5199\u4e0a\u7684\uff1a\u3000
\n
String[] str = {\"1\",\"2\",\"3\"}; \u8fd9\u79cd\u5f62\u5f0f\u53eb\u6570\u7ec4\u521d\u59cb\u5316\u5f0f\uff08ArrayInitializer\uff09\uff0c\u53ea\u80fd\u7528\u5728\u58f0\u660e\u540c\u65f6\u8d4b\u503c\u7684\u60c5\u51b5\u4e0b\u3002
\n
\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\uff08ArrayLiteral\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
\n
\u3000\u3000String[] str = {\"1\",\"2\",\"3\"}; \/\/ \u6b63\u786e\u7684
\n
\u3000\u3000String[] str = new String[]{\"1\",\"2\",\"3\"} \/\/ \u4e5f\u662f\u6b63\u786e\u7684
\n
\u800c
\n
\u3000\u3000String[] str;
\n
\u3000\u3000str = {\"1\",\"2\",\"3\"}; \/\/ \u7f16\u8bd1\u9519\u8bef
\n
\u56e0\u4e3a\u6570\u7ec4\u521d\u59cb\u5316\u5f0f\u53ea\u80fd\u7528\u4e8e\u58f0\u660e\u540c\u65f6\u8d4b\u503c\u7684\u60c5\u51b5\u4e0b\u3002 <\/p>\n

\u6539\u4e3a\uff1a
\n
\u3000\u3000String[] str;
\n
\u3000\u3000str = new String[] {\"1\",\"2\",\"3\"}; \/\/ \u6b63\u786e\u4e86
\n
\u53c8\u5982\uff1a
\n
\u3000\u3000void f(String[] str) {
\n
\u3000\u3000}
\n
\u3000\u3000f({\"1\",\"2\",\"3\"}); \/\/ \u7f16\u8bd1\u9519\u8bef
\n
\u6b63\u786e\u7684\u5e94\u8be5\u662f\uff1a
\n <\/p>\n

\u3000\u3000f(new String[] {\"1\",\"2\",\"3\"});<\/p>\n

\u8fd8\u53ef\u4ee5 String s=new String[30];<\/p>\n

\u5982\u679c\u6ca1\u6709\u663e\u5f0f\u8d4b\u503c\uff0c\u5219\u7cfb\u7edf\u81ea\u52a8\u8d4b\u9ed8\u8ba4\u503cnull\u3002 <\/p>\n


\nPS:<\/strong><\/span>
\n
\u3000\u3000\u7b14\u8005\u6240\u72af\u9519\u8bef\u4e3a\u5728\u521d\u59cb\u5316\u6570\u7ec4\u7684\u65f6\u5019\u5b9a\u4e49\u4e3aString[] str = newString[]{}\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<\/p>\n","protected":false},"excerpt":{"rendered":"java\u5b57\u7b26\u4e32\u6570\u7ec4\u521d\u59cb\u5316\u548c\u8d4b\u503c\/\/\u4e00\u7ef4\u6570\u7ec4String[]str=newString[5];\/\/\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a5\u7684String(\u5b57\u7b26\u4e32)\u578b\u7684\u4e00\u7ef4\u6570\u7ec4String[]str...","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\/328"}],"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=328"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/328\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}