{"id":38809,"date":"2024-11-26T12:25:38","date_gmt":"2024-11-26T04:25:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38809\/"},"modified":"2024-11-26T12:25:38","modified_gmt":"2024-11-26T04:25:38","slug":"java%e6%95%b0%e7%bb%84%e6%9c%80%e5%a4%a7%e5%80%bc%e4%b8%8b%e6%a0%87%e6%80%8e%e4%b9%88%e6%b1%82","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38809\/","title":{"rendered":"java\u6570\u7ec4\u6700\u5927\u503c\u4e0b\u6807\u600e\u4e48\u6c42"},"content":{"rendered":"<blockquote><p>\n  \u4f7f\u7528 arrays.binarysearch() \u65b9\u6cd5\u53ef\u4ee5\u5feb\u901f\u9ad8\u6548\u5730\u627e\u5230 java \u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c\u53ca\u5176\u4e0b\u6807\uff1a1. \u9996\u5148\u5bf9\u6570\u7ec4\u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\uff1b2. \u4f7f\u7528 arrays.sort() \u65b9\u6cd5\u8fdb\u884c\u6392\u5e8f\uff1b3. \u518d\u8fdb\u884c\u4e8c\u5206\u67e5\u627e\uff1b4. \u5bf9\u4e8e\u91cd\u590d\u5143\u7d20\uff0c\u8fdb\u4e00\u6b65\u904d\u5386\u6570\u7ec4\u627e\u5230\u6700\u540e\u51fa\u73b0\u8be5\u5143\u7d20\u7684\u4f4d\u7f6e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111506514693743.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u6700\u5927\u503c\u4e0b\u6807\u600e\u4e48\u6c42\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u6700\u5927\u503c\u4e0b\u6807\u600e\u4e48\u6c42\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u6c42\u89e3 Java \u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c\u4e0b\u6807\uff1f<\/strong><\/p>\n<p><strong>\u5f00\u95e8\u89c1\u5c71\uff1a<\/strong><br \/>\u4f7f\u7528 Arrays.binarySearch() \u65b9\u6cd5\u53ef\u4ee5\u5feb\u901f\u9ad8\u6548\u5730\u627e\u5230 Java \u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c\u53ca\u5176\u4e0b\u6807\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u9610\u8ff0\uff1a<\/strong><\/p>\n<p><strong>1. \u6570\u7ec4\u6392\u5e8f\uff1a<\/strong><br \/>\u9996\u5148\uff0c\u9700\u8981\u5bf9\u6570\u7ec4\u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\u3002\u53ef\u4ee5\u4f7f\u7528 Arrays.sort() \u65b9\u6cd5\u6765\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>2. \u4e8c\u5206\u67e5\u627e\uff1a<\/strong><br \/>\u6392\u5e8f\u540e\uff0c\u4f7f\u7528 Arrays.binarySearch() \u65b9\u6cd5\u5bf9\u6392\u5e8f\u540e\u7684\u6570\u7ec4\u8fdb\u884c\u4e8c\u5206\u67e5\u627e\u3002\u8be5\u65b9\u6cd5\u4f1a\u8fd4\u56de\u6700\u5927\u503c\u5728\u6570\u7ec4\u4e2d\u7684\u4e0b\u6807\u3002<\/p>\n<p><strong>3. \u5904\u7406\u7279\u6b8a\u60c5\u51b5\uff1a<\/strong><br \/>\u5982\u679c\u6570\u7ec4\u4e2d\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u5219\u4e8c\u5206\u67e5\u627e\u53ef\u80fd\u4f1a\u8fd4\u56de\u591a\u4e2a\u6700\u5927\u503c\u7684\u4e0b\u6807\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u8fdb\u4e00\u6b65\u904d\u5386\u6570\u7ec4\u4ee5\u627e\u5230\u6700\u540e\u51fa\u73b0\u6700\u5927\u503c\u7684\u5143\u7d20\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>int[] numbers = {5, 2, 8, 3, 1, 9};\n\n\/\/ \u6392\u5e8f\u6570\u7ec4\nArrays.sort(numbers);\n\n\/\/ \u8fdb\u884c\u4e8c\u5206\u67e5\u627e\nint maxIndex = Arrays.binarySearch(numbers, numbers[numbers.length - 1]);\n\n\/\/ \u8f93\u51fa\u6700\u5927\u503c\u4e0b\u6807\nSystem.out.println(\"\u6700\u5927\u503c\u4e0b\u6807\uff1a\" + maxIndex);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>\u6700\u5927\u503c\u4e0b\u6807\uff1a5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><br \/>\u5982\u679c\u6570\u7ec4\u4e3a\u7a7a\u6216\u6700\u5927\u503c\u4e0d\u5b58\u5728\uff0cArrays.binarySearch() \u5c06\u8fd4\u56de\u8d1f\u6570\u3002\u9700\u8981\u5bf9\u8fd9\u4e9b\u60c5\u51b5\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u6700\u5927\u503c\u4e0b\u6807\u600e\u4e48\u6c42\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>\u4f7f\u7528 arrays.binarysearch() \u65b9\u6cd5\u53ef\u4ee5\u5feb\u901f\u9ad8\u6548\u5730\u627e\u5230 java \u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c\u53ca\u5176\u4e0b\u6807\uff1a1. \u9996\u5148\u5bf9\u6570\u7ec4\u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\uff1b2. \u4f7f\u7528 arrays.sort() \u65b9\u6cd5\u8fdb\u884c\u6392\u5e8f\uff1b3. \u518d\u8fdb\u884c\u4e8c\u5206\u67e5\u627e\uff1b4. \u5bf9\u4e8e\u91cd\u590d\u5143\u7d20\uff0c\u8fdb\u4e00\u6b65\u904d\u5386\u6570\u7ec4\u627e\u5230\u6700\u540e\u51fa\u73b0\u8be5\u5143\u7d20\u7684\u4f4d\u7f6e\u3002 \u5982\u4f55\u6c42\u89e3 Java \u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c\u4e0b\u6807\uff1f \u5f00\u95e8\u89c1\u5c71\uff1a\u4f7f\u7528 Arrays.binarySearch() \u65b9\u6cd5\u53ef\u4ee5\u5feb\u901f\u9ad8\u6548\u5730\u627e\u5230 Java \u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c\u53ca\u5176\u4e0b\u6807\u3002 \u8be6\u7ec6\u9610\u8ff0\uff1a 1. \u6570\u7ec4\u6392\u5e8f\uff1a\u9996\u5148\uff0c\u9700\u8981\u5bf9\u6570\u7ec4\u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\u3002\u53ef\u4ee5\u4f7f\u7528 Arrays.sort() \u65b9\u6cd5\u6765\u5bf9\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 2. \u4e8c\u5206\u67e5\u627e\uff1a\u6392\u5e8f\u540e\uff0c\u4f7f\u7528 Arrays.binarySearch() \u65b9\u6cd5\u5bf9\u6392\u5e8f\u540e\u7684\u6570\u7ec4\u8fdb\u884c\u4e8c\u5206\u67e5\u627e\u3002\u8be5\u65b9\u6cd5\u4f1a\u8fd4\u56de\u6700\u5927\u503c\u5728\u6570\u7ec4\u4e2d\u7684\u4e0b\u6807\u3002 3. \u5904\u7406\u7279\u6b8a\u60c5\u51b5\uff1a\u5982\u679c\u6570\u7ec4\u4e2d\u5305\u542b\u91cd\u590d\u5143\u7d20\uff0c\u5219\u4e8c\u5206\u67e5\u627e\u53ef\u80fd\u4f1a\u8fd4\u56de\u591a\u4e2a\u6700\u5927\u503c\u7684\u4e0b\u6807\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u8fdb\u4e00\u6b65\u904d\u5386\u6570\u7ec4\u4ee5\u627e\u5230\u6700\u540e\u51fa\u73b0\u6700\u5927\u503c\u7684\u5143\u7d20\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a int[] numbers = {5, 2, 8, 3, 1, 9}; \/\/ \u6392\u5e8f\u6570\u7ec4 Arrays.sort(numbers); \/\/ \u8fdb\u884c\u4e8c\u5206\u67e5\u627e int maxIndex = Arrays.binarySearch(numbers, numbers[numbers.length &#8211; 1]); \/\/ \u8f93\u51fa\u6700\u5927\u503c\u4e0b\u6807 [&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-38809","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38809","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=38809"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38809\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}