{"id":202983,"date":"2025-05-22T09:21:51","date_gmt":"2025-05-22T01:21:51","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202983\/"},"modified":"2025-05-22T09:21:51","modified_gmt":"2025-05-22T01:21:51","slug":"java%e5%87%bd%e6%95%b0%e5%bc%8f%e9%80%92%e5%bd%92%e5%a6%82%e4%bd%95%e5%ba%94%e7%94%a8%e4%ba%8e%e4%b8%8d%e5%90%8c%e7%bc%96%e7%a8%8b%e5%9c%ba%e6%99%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202983\/","title":{"rendered":"Java\u51fd\u6570\u5f0f\u9012\u5f52\u5982\u4f55\u5e94\u7528\u4e8e\u4e0d\u540c\u7f16\u7a0b\u573a\u666f\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Java\u51fd\u6570\u5f0f\u9012\u5f52\u5982\u4f55\u5e94\u7528\u4e8e\u4e0d\u540c\u7f16\u7a0b\u573a\u666f\uff1f<\/h1>\n<p>\u6765\u5230\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300aJava\u51fd\u6570\u5f0f\u9012\u5f52\u5982\u4f55\u5e94\u7528\u4e8e\u4e0d\u540c\u7f16\u7a0b\u573a\u666f\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730011599671de1cf103b9.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>Java\u51fd\u6570\u5f0f\u9012\u5f52\u5728\u7f16\u7a0b\u573a\u666f\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n<p>\u51fd\u6570\u5f0f\u9012\u5f52\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u7f16\u7a0b\u8303\u4f8b\uff0c\u5141\u8bb8\u7f16\u5199\u7b80\u6d01\u3001\u53ef\u8bfb\u4e14\u9ad8\u6548\u7684\u4ee3\u7801\u3002\u5728Java\u4e2d\uff0c\u901a\u8fc7\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u5b9e\u73b0\u51fd\u6570\u5f0f\u9012\u5f52\u3002<\/p>\n<p><strong>\u57fa\u672c\u6982\u5ff5<\/strong><\/p>\n<p>\u9012\u5f52\u51fd\u6570\u672c\u8d28\u4e0a\u662f\u8c03\u7528\u81ea\u8eab\u7684\u51fd\u6570\u3002\u5728Java\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\u5b9e\u73b0\u51fd\u6570\u5f0f\u9012\u5f52\uff1a<\/p>\n<pre>public static int factorial(int n) {\n    return n == 0 ? 1 : n * factorial(n - 1);\n}<\/pre>\n<p>\u672c\u4f8b\u793a\u8303\u4e86\u5982\u4f55\u4f7f\u7528\u51fd\u6570\u5f0f\u9012\u5f52\u8ba1\u7b97\u9636\u4e58\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u6df1\u5ea6\u4f18\u5148\u641c\u7d22<\/strong><\/p>\n<p>\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u662f\u4e00\u79cd\u904d\u5386\u6811\u6216\u56fe\u6570\u636e\u7ed3\u6784\u7684\u65b9\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u5f0f\u9012\u5f52\u6765\u5b9e\u73b0\u5b83\uff1a<\/p>\n<pre>public static void dfs(Node root) {\n    root.visit();\n    for (Node child : root.getChildren()) {\n        dfs(child);\n    }\n}<\/pre>\n<p>\u5728\u672c\u4f8b\u4e2d\uff0c<code>dfs<\/code>\u65b9\u6cd5\u8bbf\u95ee\u4e00\u4e2a\u8282\u70b9\uff0c\u7136\u540e\u9012\u5f52\u5730\u8bbf\u95ee\u5176\u6240\u6709\u5b50\u8282\u70b9\u3002<\/p>\n<p><strong>\u5feb\u901f\u6392\u5e8f<\/strong><\/p>\n<p>\u5feb\u901f\u6392\u5e8f\u662f\u4e00\u79cd\u9ad8\u6548\u7684\u6392\u5e8f\u7b97\u6cd5\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u5f0f\u9012\u5f52\u7f16\u5199\u5176Java\u5b9e\u73b0\uff1a<\/p>\n<pre>public static int[] quickSort(int[] arr, int low, int high) {\n    if (low &lt; high) {\n        int pivot = partition(arr, low, high);\n        quickSort(arr, low, pivot - 1);\n        quickSort(arr, pivot + 1, high);\n    }\n    return arr;\n}<\/pre>\n<p>\u6b64\u4ee3\u7801\u4f7f\u7528\u51fd\u6570\u5f0f\u9012\u5f52\u5c06\u6570\u7ec4\u5206\u6210\u8f83\u5c0f\u90e8\u5206\uff0c\u7136\u540e\u9012\u5f52\u5730\u5bf9\u5b83\u4eec\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p><strong>\u4f18\u70b9<\/strong><\/p>\n<p>\u51fd\u6570\u5f0f\u9012\u5f52\u5177\u6709\u4ee5\u4e0b\u4f18\u70b9\uff1a<\/p>\n<ul>\n<li><strong>\u7b80\u6d01\u6027\uff1a<\/strong>\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u6613\u8bfb\u3002<\/li>\n<li><strong>\u6548\u7387\uff1a<\/strong>\u7531\u4e8e\u907f\u514d\u4e86\u6808\u5e27\u7684\u521b\u5efa\u548c\u9500\u6bc1\uff0c\u51fd\u6570\u5f0f\u9012\u5f52\u901a\u5e38\u6bd4\u4f20\u7edf\u9012\u5f52\u66f4\u5177\u6548\u7387\u3002<\/li>\n<li><strong>\u5e76\u884c\u6027\uff1a<\/strong>lambda\u8868\u8fbe\u5f0f\u53ef\u4ee5\u5e76\u884c\u6c42\u503c\uff0c\u8fd9\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u51fd\u6570\u5f0f\u9012\u5f52\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5806\u6808\u6ea2\u51fa\uff0c\u56e0\u6b64\u9700\u8981\u8c28\u614e\u4f7f\u7528\u3002<\/li>\n<li>\u5bf9\u4e8e\u5927\u91cf\u9012\u5f52\u8c03\u7528\uff0c\u8003\u8651\u91c7\u7528\u5c3e\u90e8\u9012\u5f52\u4f18\u5316\u6765\u907f\u514d\u5806\u6808\u6ea2\u51fa\u3002<\/li>\n<\/ul>\n<p>\u4eca\u5929\u5173\u4e8e\u300aJava\u51fd\u6570\u5f0f\u9012\u5f52\u5982\u4f55\u5e94\u7528\u4e8e\u4e0d\u540c\u7f16\u7a0b\u573a\u666f\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java\u51fd\u6570\u5f0f\u9012\u5f52\u5982\u4f55\u5e94\u7528\u4e8e\u4e0d\u540c&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202983","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202983"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202983\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}