{"id":36796,"date":"2024-11-26T17:54:37","date_gmt":"2024-11-26T09:54:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36796\/"},"modified":"2024-11-26T17:54:37","modified_gmt":"2024-11-26T09:54:37","slug":"java%e6%95%b0%e7%bb%84%e7%b1%bb%e6%80%8e%e4%b9%88%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36796\/","title":{"rendered":"java\u6570\u7ec4\u7c7b\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u6570\u7ec4\u7528\u4e8e\u5b58\u50a8\u76f8\u540c\u7c7b\u578b\u6570\u636e\u7684\u5143\u7d20\u3002\u8981\u521b\u5efa\u6570\u7ec4\uff0c\u8bf7\u4f7f\u7528 new \u8fd0\u7b97\u7b26\u5e76\u6307\u5b9a\u7c7b\u578b\u548c\u5927\u5c0f\u3002\u8bbf\u95ee\u5143\u7d20\u65f6\u4f7f\u7528\u4e2d\u62ec\u53f7\uff0c\u5982 array[index]\u3002\u6570\u7ec4\u5c5e\u6027\u5305\u62ec length\uff08\u5143\u7d20\u6570\uff09\u548c tostring\uff08\u5b57\u7b26\u4e32\u8868\u793a\uff09\u3002\u904d\u5386\u6570\u7ec4\u53ef\u4ee5\u4f7f\u7528 for \u6216 foreach \u5faa\u73af\u3002\u591a\u7ef4\u6570\u7ec4\u5c06\u5143\u7d20\u5b58\u50a8\u5728\u5d4c\u5957\u6570\u7ec4\u4e2d\uff0c\u5176\u521b\u5efa\u548c\u8bbf\u95ee\u4e0e\u4e00\u7ef4\u6570\u7ec4\u7c7b\u4f3c\u3002\u5e38\u89c1\u64cd\u4f5c\u5305\u62ec\u6392\u5e8f\u3001\u641c\u7d22\u3001\u590d\u5236\u548c\u586b\u5145\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111218572110001.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u7c7b\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u7c7b\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 Java \u4e2d\u4f7f\u7528\u6570\u7ec4\u7c7b\u7684\u6307\u5357<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u6570\u7ec4\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5b83\u5b58\u50a8\u4e00\u7cfb\u5217\u76f8\u540c\u6570\u636e\u7c7b\u578b\u7684\u5143\u7d20\u3002\u5b83\u4eec\u5e7f\u6cdb\u7528\u4e8e\u5b58\u50a8\u548c\u7ba1\u7406\u6570\u636e\u96c6\u5408\u3002<\/p>\n<p><strong>\u521b\u5efa\u6570\u7ec4<\/strong><\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u521b\u5efa\u6570\u7ec4\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\/\/ \u58f0\u660e\u4e00\u4e2a int \u7c7b\u578b\u7684\u6570\u7ec4\uff0c\u5927\u5c0f\u4e3a 10\nint[] numbers = new int[10];\n\n\/\/ \u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e00\u4e2a String \u7c7b\u578b\u7684\u6570\u7ec4\nString[] names = {\"Alice\", \"Bob\", \"Charlie\"};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u53f7\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u7ec4\u5143\u7d20\uff1a<\/p>\n<pre>\/\/ \u8bbf\u95ee\u6570\u7ec4\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20\nint firstNumber = numbers[0];\n\n\/\/ \u4fee\u6539\u6570\u7ec4\u4e2d\u7b2c\u4e8c\u4e2a\u5143\u7d20\nnames[1] = \"Dave\";<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6570\u7ec4\u5c5e\u6027<\/strong><\/p>\n<p>\u6570\u7ec4\u5bf9\u8c61\u5177\u6709\u4ee5\u4e0b\u91cd\u8981\u5c5e\u6027\uff1a<\/p>\n<ul>\n<li> <strong>length:<\/strong> \u8fd4\u56de\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u6570\u91cf<\/li>\n<li> <strong>clone():<\/strong> \u521b\u5efa\u6570\u7ec4\u7684\u526f\u672c<\/li>\n<li> <strong>equals(Object):<\/strong> \u6bd4\u8f83\u4e24\u4e2a\u6570\u7ec4\u662f\u5426\u76f8\u7b49<\/li>\n<li> <strong>toString():<\/strong> \u8fd4\u56de\u6570\u7ec4\u7684\u5b57\u7b26\u4e32\u8868\u793a\u5f62\u5f0f<\/li>\n<\/ul>\n<p><strong>\u904d\u5386\u6570\u7ec4<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 for \u5faa\u73af\u6216 foreach \u5faa\u73af\u904d\u5386\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff1a<\/p>\n<pre>\/\/ \u4f7f\u7528 for \u5faa\u73af\nfor (int i = 0; i &lt; numbers.length; i++) {\n    System.out.println(numbers[i]);\n}\n\n\/\/ \u4f7f\u7528 foreach \u5faa\u73af\nfor (String name : names) {\n    System.out.println(name);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u591a\u7ef4\u6570\u7ec4<\/strong><\/p>\n<p>Java \u4e5f\u652f\u6301\u591a\u7ef4\u6570\u7ec4\uff0c\u5176\u4e2d\u6570\u7ec4\u5143\u7d20\u672c\u8eab\u5c31\u662f\u6570\u7ec4\u3002\u521b\u5efa\u548c\u8bbf\u95ee\u591a\u7ef4\u6570\u7ec4\u4e0e\u4e00\u7ef4\u6570\u7ec4\u7c7b\u4f3c\uff1a<\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a\u4e8c\u7ef4 int \u7c7b\u578b\u7684\u6570\u7ec4\nint[][] matrix = new int[3][4];\n\n\/\/ \u8bbf\u95ee\u4e8c\u7ef4\u6570\u7ec4\u4e2d (1, 2) \u7684\u5143\u7d20\nint element = matrix[1][2];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5e38\u89c1\u6570\u7ec4\u64cd\u4f5c<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u6570\u7ec4\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li> <strong>\u6392\u5e8f:<\/strong> \u4f7f\u7528 Arrays.sort() \u65b9\u6cd5\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f<\/li>\n<li> <strong>\u641c\u7d22:<\/strong> \u4f7f\u7528 Arrays.binarySearch() \u65b9\u6cd5\u5728\u6570\u7ec4\u4e2d\u641c\u7d22\u5143\u7d20<\/li>\n<li> <strong>\u62f7\u8d1d:<\/strong> \u4f7f\u7528 System.arraycopy() \u65b9\u6cd5\u62f7\u8d1d\u6570\u7ec4<\/li>\n<li> <strong>\u586b\u5145:<\/strong> \u4f7f\u7528 Arrays.fill() \u65b9\u6cd5\u7528\u7279\u5b9a\u503c\u586b\u5145\u6570\u7ec4<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u7c7b\u600e\u4e48\u7528\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>\u5728 java \u4e2d\uff0c\u6570\u7ec4\u7528\u4e8e\u5b58\u50a8\u76f8\u540c\u7c7b\u578b\u6570\u636e\u7684\u5143\u7d20\u3002\u8981\u521b\u5efa\u6570\u7ec4\uff0c\u8bf7\u4f7f\u7528 new \u8fd0\u7b97\u7b26\u5e76\u6307\u5b9a\u7c7b\u578b\u548c\u5927\u5c0f\u3002\u8bbf\u95ee\u5143\u7d20\u65f6\u4f7f\u7528\u4e2d\u62ec\u53f7\uff0c\u5982 array[index]\u3002\u6570\u7ec4\u5c5e\u6027\u5305\u62ec length\uff08\u5143\u7d20\u6570\uff09\u548c tostring\uff08\u5b57\u7b26\u4e32\u8868\u793a\uff09\u3002\u904d\u5386\u6570\u7ec4\u53ef\u4ee5\u4f7f\u7528 for \u6216 foreach \u5faa\u73af\u3002\u591a\u7ef4\u6570\u7ec4\u5c06\u5143\u7d20\u5b58\u50a8\u5728\u5d4c\u5957\u6570\u7ec4\u4e2d\uff0c\u5176\u521b\u5efa\u548c\u8bbf\u95ee\u4e0e\u4e00\u7ef4\u6570\u7ec4\u7c7b\u4f3c\u3002\u5e38\u89c1\u64cd\u4f5c\u5305\u62ec\u6392\u5e8f\u3001\u641c\u7d22\u3001\u590d\u5236\u548c\u586b\u5145\u3002 \u5728 Java \u4e2d\u4f7f\u7528\u6570\u7ec4\u7c7b\u7684\u6307\u5357 \u5728 Java \u4e2d\uff0c\u6570\u7ec4\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5b83\u5b58\u50a8\u4e00\u7cfb\u5217\u76f8\u540c\u6570\u636e\u7c7b\u578b\u7684\u5143\u7d20\u3002\u5b83\u4eec\u5e7f\u6cdb\u7528\u4e8e\u5b58\u50a8\u548c\u7ba1\u7406\u6570\u636e\u96c6\u5408\u3002 \u521b\u5efa\u6570\u7ec4 \u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u521b\u5efa\u6570\u7ec4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \/\/ \u58f0\u660e\u4e00\u4e2a int \u7c7b\u578b\u7684\u6570\u7ec4\uff0c\u5927\u5c0f\u4e3a 10 int[] numbers = new int[10]; \/\/ \u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e00\u4e2a String \u7c7b\u578b\u7684\u6570\u7ec4 String[] names = {&#8220;Alice&#8221;, &#8220;Bob&#8221;, &#8220;Charlie&#8221;}; \u767b\u5f55\u540e\u590d\u5236 \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20 \u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u53f7\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u7ec4\u5143\u7d20\uff1a \/\/ \u8bbf\u95ee\u6570\u7ec4\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20 int firstNumber = numbers[0]; \/\/ \u4fee\u6539\u6570\u7ec4\u4e2d\u7b2c\u4e8c\u4e2a\u5143\u7d20 names[1] = &#8220;Dave&#8221;; [&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-36796","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36796","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=36796"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36796\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}