{"id":37975,"date":"2024-11-26T10:16:17","date_gmt":"2024-11-26T02:16:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/37975\/"},"modified":"2024-11-26T10:16:17","modified_gmt":"2024-11-26T02:16:17","slug":"java%e6%80%8e%e4%b9%88%e6%8f%90%e5%8f%96%e6%95%b0%e7%bb%84%e4%b8%ad%e7%9a%84%e5%85%83%e7%b4%a0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/37975\/","title":{"rendered":"Java\u600e\u4e48\u63d0\u53d6\u6570\u7ec4\u4e2d\u7684\u5143\u7d20"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u63d0\u53d6\u6570\u7ec4\u5143\u7d20\u65b9\u6cd5\uff1a\u4f7f\u7528\u65b9\u62ec\u53f7\u8fd0\u7b97\u7b26\uff08[]) \u63d0\u53d6\u539f\u59cb\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u5143\u7d20\u3002\u4f7f\u7528\u65b9\u62ec\u53f7\u8fd0\u7b97\u7b26\u63d0\u53d6\u5bf9\u8c61\u6570\u7ec4\u5143\u7d20\uff0c\u8fd4\u56de\u5f15\u7528\u3002\u4f7f\u7528\u5faa\u73af\u904d\u5386\u6570\u7ec4\u63d0\u53d6\u5143\u7d20\u3002\u5bf9\u4e8e\u539f\u59cb\u6570\u636e\u7c7b\u578b\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 arrays.tostring() \u65b9\u6cd5\u548c\u5b57\u7b26\u4e32\u5206\u5272\u63d0\u53d6\u5143\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111314242717985.jpg\" class=\"aligncenter\" title=\"Java\u600e\u4e48\u63d0\u53d6\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u63d2\u56fe\" alt=\"Java\u600e\u4e48\u63d0\u53d6\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u63d0\u53d6 Java \u6570\u7ec4\u4e2d\u7684\u5143\u7d20<\/strong><\/p>\n<p>Java \u4e2d\u63d0\u53d6\u6570\u7ec4\u5143\u7d20\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u5143\u7d20\u7684\u7c7b\u578b\u3002<\/p>\n<p><strong>\u539f\u59cb\u6570\u636e\u7c7b\u578b\u6570\u7ec4\uff08int[]\u3001double[] \u7b49\uff09<\/strong><\/p>\n<p>\u5bf9\u4e8e\u539f\u59cb\u6570\u636e\u7c7b\u578b\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7\u8fd0\u7b97\u7b26\uff08[]) \u63d0\u53d6\u5143\u7d20\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] numbers = {1, 2, 3, 4, 5};\nint firstNumber = numbers[0]; \/\/ 1\nint lastNumber = numbers[numbers.length - 1]; \/\/ 5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5bf9\u8c61\u6570\u7ec4<\/strong><\/p>\n<p>\u5bf9\u4e8e\u5bf9\u8c61\u6570\u7ec4\uff0c\u4e5f\u4f7f\u7528\u65b9\u62ec\u53f7\u8fd0\u7b97\u7b26\u63d0\u53d6\u5143\u7d20\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5f15\u7528\uff1a<\/p>\n<pre>String[] names = {\"John\", \"Mary\", \"Bob\"};\nString firstName = names[0]; \/\/ \"John\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u5faa\u73af\u63d0\u53d6\u5143\u7d20<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u904d\u5386\u6570\u7ec4\u5e76\u63d0\u53d6\u5143\u7d20\uff1a<\/p>\n<pre>\/\/ \u539f\u59cb\u6570\u636e\u7c7b\u578b\u6570\u7ec4\nint[] numbers = {1, 2, 3, 4, 5};\nfor (int number : numbers) {\n    System.out.println(number);\n}\n\n\/\/ \u5bf9\u8c61\u6570\u7ec4\nString[] names = {\"John\", \"Mary\", \"Bob\"};\nfor (String name : names) {\n    System.out.println(name);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Arrays.toString() \u65b9\u6cd5<\/strong><\/p>\n<p>\u5bf9\u4e8e\u539f\u59cb\u6570\u636e\u7c7b\u578b\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 Arrays.toString() \u65b9\u6cd5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u4f7f\u7528\u5b57\u7b26\u4e32\u5206\u5272\u65b9\u6cd5\u63d0\u53d6\u5143\u7d20\uff1a<\/p>\n<pre>int[] numbers = {1, 2, 3, 4, 5};\nString numbersString = Arrays.toString(numbers); \/\/ \"[1, 2, 3, 4, 5]\"\nString[] numbersArray = numbersString.split(\",\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava\u600e\u4e48\u63d0\u53d6\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\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\u63d0\u53d6\u6570\u7ec4\u5143\u7d20\u65b9\u6cd5\uff1a\u4f7f\u7528\u65b9\u62ec\u53f7\u8fd0\u7b97\u7b26\uff08[]) \u63d0\u53d6\u539f\u59cb\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u5143\u7d20\u3002\u4f7f\u7528\u65b9\u62ec\u53f7\u8fd0\u7b97\u7b26\u63d0\u53d6\u5bf9\u8c61\u6570\u7ec4\u5143\u7d20\uff0c\u8fd4\u56de\u5f15\u7528\u3002\u4f7f\u7528\u5faa\u73af\u904d\u5386\u6570\u7ec4\u63d0\u53d6\u5143\u7d20\u3002\u5bf9\u4e8e\u539f\u59cb\u6570\u636e\u7c7b\u578b\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 arrays.tostring() \u65b9\u6cd5\u548c\u5b57\u7b26\u4e32\u5206\u5272\u63d0\u53d6\u5143\u7d20\u3002 \u5982\u4f55\u63d0\u53d6 Java \u6570\u7ec4\u4e2d\u7684\u5143\u7d20 Java \u4e2d\u63d0\u53d6\u6570\u7ec4\u5143\u7d20\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u5143\u7d20\u7684\u7c7b\u578b\u3002 \u539f\u59cb\u6570\u636e\u7c7b\u578b\u6570\u7ec4\uff08int[]\u3001double[] \u7b49\uff09 \u5bf9\u4e8e\u539f\u59cb\u6570\u636e\u7c7b\u578b\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7\u8fd0\u7b97\u7b26\uff08[]) \u63d0\u53d6\u5143\u7d20\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] numbers = {1, 2, 3, 4, 5}; int firstNumber = numbers[0]; \/\/ 1 int lastNumber = numbers[numbers.length &#8211; 1]; \/\/ 5 \u767b\u5f55\u540e\u590d\u5236 \u5bf9\u8c61\u6570\u7ec4 \u5bf9\u4e8e\u5bf9\u8c61\u6570\u7ec4\uff0c\u4e5f\u4f7f\u7528\u65b9\u62ec\u53f7\u8fd0\u7b97\u7b26\u63d0\u53d6\u5143\u7d20\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5f15\u7528\uff1a String[] names = {&#8220;John&#8221;, &#8220;Mary&#8221;, &#8220;Bob&#8221;}; String firstName = names[0]; \/\/ &#8220;John&#8221; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u5faa\u73af\u63d0\u53d6\u5143\u7d20 \u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u904d\u5386\u6570\u7ec4\u5e76\u63d0\u53d6\u5143\u7d20\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-37975","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37975","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=37975"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37975\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=37975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=37975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=37975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}