{"id":4133,"date":"2024-05-21T08:03:39","date_gmt":"2024-05-21T00:03:39","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/index.php\/%e9%9d%a2%e8%af%95\/hashset%e3%80%81linkedhashset%e5%92%8ctreeset%e4%b9%8b%e9%97%b4%e7%9a%84%e5%8c%ba%e5%88%ab%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f\/"},"modified":"2024-08-02T17:06:03","modified_gmt":"2024-08-02T09:06:03","slug":"hashset%e3%80%81linkedhashset%e5%92%8ctreeset%e4%b9%8b%e9%97%b4%e7%9a%84%e5%8c%ba%e5%88%ab%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/%e9%9d%a2%e8%af%95\/hashset%e3%80%81linkedhashset%e5%92%8ctreeset%e4%b9%8b%e9%97%b4%e7%9a%84%e5%8c%ba%e5%88%ab%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f\/","title":{"rendered":"HashSet\u3001LinkedHashSet\u548cTreeSet\u4e4b\u95f4\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<div class=\"wxsyncmain\">\n<p data-v-md-line=\"1\"><span style=\"font-size: 16px; letter-spacing: normal;\">HashSet\u3001LinkedHashSet\u548cTreeSet\u90fd\u662fJava\u96c6\u5408\u6846\u67b6\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u5e76\u4e14\u5b83\u4eec\u90fd\u5b9e\u73b0\u4e86Set\u63a5\u53e3\u3002\u4e0b\u9762\u8be6\u7ec6\u8bf4\u660e\u8fd9\u4e09\u8005\u4e4b\u95f4\u7684\u533a\u522b\uff1a<\/span><\/p>\n<h3 style=\"margin-top: 24px; margin-bottom: 24px;\" data-v-md-heading=\"hashset\" data-v-md-line=\"3\"><strong><span style=\"font-size: 20px;\">HashSet<\/span><\/strong><\/h3>\n<ul class=\"list-paddingleft-1\" data-v-md-line=\"4\">\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u5b9e\u73b0\u539f\u7406<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1aHashSet\u5185\u90e8\u4f7f\u7528HashMap\u6765\u5b58\u50a8\u5176\u5143\u7d20\u3002\u6bcf\u4e2a\u63d2\u5165\u7684\u5143\u7d20\u90fd\u4f5c\u4e3a\u952e\u5b58\u50a8\u5728HashMap\u4e2d\uff0c\u5176\u503c\u662f\u4e00\u4e2a\u56fa\u5b9a\u7684\u79c1\u6709\u9759\u6001\u5bf9\u8c61\uff08\u56e0\u4e3a\u53ea\u9700\u8981\u952e\u800c\u4e0d\u9700\u8981\u503c\uff09\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u5143\u7d20\u552f\u4e00\u6027<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u5143\u7d20\u7684\u552f\u4e00\u6027\u901a\u8fc7\u8986\u5199\u5bf9\u8c61\u7684hashCode()\u65b9\u6cd5\u548cequals()\u65b9\u6cd5\u6765\u4fdd\u8bc1\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u6392\u5e8f<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1aHashSet\u4e0d\u4fdd\u8bc1\u5143\u7d20\u7684\u987a\u5e8f\uff1b\u5b83\u4eec\u53ef\u80fd\u4f1a\u968f\u65f6\u6539\u53d8\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u6027\u80fd<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u63d0\u4f9b\u4e86\u5f88\u597d\u7684\u67e5\u627e\u6027\u80fd\u2014\u2014\u901a\u5e38\u63d0\u4f9b\u5e38\u6570\u65f6\u95f4\u7684\u6027\u80fd\uff0c\u53d6\u51b3\u4e8e\u54c8\u5e0c\u51fd\u6570\u7684\u8d28\u91cf\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u7a7a\u95f4\u6548\u7387<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u7531\u4e8e\u4f7f\u7528\u4e86\u54c8\u5e0c\u8868\uff0c\u53ef\u80fd\u5b58\u5728\u8f83\u5927\u7684\u5185\u5b58\u5f00\u9500\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u793a\u4f8b<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a<\/span><\/li>\n<\/ul>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"cs\"><code><span class=\"code-snippet_outer\">Set&lt;String&gt; hashSet = <span class=\"code-snippet__keyword\">new<\/span> HashSet&lt;&gt;();<\/span><\/code><code><span class=\"code-snippet_outer\">hashSet.<span class=\"code-snippet__keyword\">add<\/span>(<span class=\"code-snippet__string\">\"Apple\"<\/span>);<\/span><\/code><code><span class=\"code-snippet_outer\">hashSet.<span class=\"code-snippet__keyword\">add<\/span>(<span class=\"code-snippet__string\">\"Banana\"<\/span>);<\/span><\/code><code><span class=\"code-snippet_outer\">hashSet.<span class=\"code-snippet__keyword\">add<\/span>(<span class=\"code-snippet__string\">\"Cherry\"<\/span>);\n<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\">\/\/ \u5143\u7d20\u987a\u5e8f\u4e0d\u80fd\u4fdd\u8bc1<\/span><\/span><\/code><\/pre>\n<\/section>\n<h3 style=\"margin-top: 24px; margin-bottom: 24px;\" data-v-md-heading=\"linkedhashset\" data-v-md-line=\"18\"><strong><span style=\"font-size: 20px;\">LinkedHashSet<\/span><\/strong><\/h3>\n<ul class=\"list-paddingleft-1\" data-v-md-line=\"19\">\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u5b9e\u73b0\u539f\u7406<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1aLinkedHashSet\u5185\u90e8\u4f7f\u7528LinkedHashMap\u6765\u5b58\u50a8\u5143\u7d20\u3002\u5b83\u7ed3\u5408\u4e86\u54c8\u5e0c\u8868\u4e0e\u53cc\u5411\u94fe\u8868\u7684\u7279\u6027\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u5143\u7d20\u552f\u4e00\u6027<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u548cHashSet\u7c7b\u4f3c\uff0c\u901a\u8fc7\u8986\u5199\u5bf9\u8c61\u7684hashCode()\u548cequals()\u65b9\u6cd5\u6765\u4fdd\u8bc1\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u6392\u5e8f<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u7ef4\u62a4\u4e86\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u8bb0\u5f55\u63d2\u5165\u987a\u5e8f\uff0c\u56e0\u6b64\u5143\u7d20\u4f1a\u6309\u7167\u5b83\u4eec\u88ab\u6dfb\u52a0\u5230\u96c6\u5408\u4e2d\u7684\u987a\u5e8f\u6765\u8fdb\u884c\u8fed\u4ee3\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u6027\u80fd<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u67e5\u627e\u6027\u80fd\u4e0eHashSet\u76f8\u5f53\uff0c\u4f46\u7531\u4e8e\u7ef4\u62a4\u4e86\u94fe\u8868\uff0c\u63d2\u5165\u6027\u80fd\u7565\u4f4e\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u7a7a\u95f4\u6548\u7387<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u76f8\u6bd4HashSet\uff0c\u589e\u52a0\u4e86\u989d\u5916\u7684\u5f00\u9500\uff08\u53cc\u5411\u94fe\u8868\u6307\u9488\uff09\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u793a\u4f8b<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a<\/span><\/li>\n<\/ul>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"cs\"><code><span class=\"code-snippet_outer\">Set&lt;String&gt; linkedHashSet = <span class=\"code-snippet__keyword\">new<\/span> LinkedHashSet&lt;&gt;();<\/span><\/code><code><span class=\"code-snippet_outer\">\nlinkedHashSet.<span class=\"code-snippet__keyword\">add<\/span>(<span class=\"code-snippet__string\">\"Apple\"<\/span>);<\/span><\/code><code><span class=\"code-snippet_outer\">\nlinkedHashSet.<span class=\"code-snippet__keyword\">add<\/span>(<span class=\"code-snippet__string\">\"Banana\"<\/span>);<\/span><\/code><code><span class=\"code-snippet_outer\">\nlinkedHashSet.<span class=\"code-snippet__keyword\">add<\/span>(<span class=\"code-snippet__string\">\"Cherry\"<\/span>);<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\">\n\/\/ \u8fed\u4ee3\u987a\u5e8f\u5c06\u4f1a\u662f Apple -&gt; Banana -&gt; Cherry<\/span><\/span><\/code><\/pre>\n<\/section>\n<h3 style=\"margin-top: 24px; margin-bottom: 24px;\" data-v-md-heading=\"treeset\" data-v-md-line=\"33\"><strong><span style=\"font-size: 20px;\">TreeSet<\/span><\/strong><\/h3>\n<ul class=\"list-paddingleft-1\" data-v-md-line=\"34\">\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u5b9e\u73b0\u539f\u7406<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1aTreeSet\u662f\u57fa\u4e8e\u7ea2\u9ed1\u6811\uff08\u81ea\u5e73\u8861\u7684\u4e8c\u53c9\u641c\u7d22\u6811\uff09\u5b9e\u73b0\u7684\u3002\u5185\u90e8\u4f7f\u7528NavigableMap\uff0c\u901a\u5e38\u5177\u4f53\u662fTreeMap\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u5143\u7d20\u552f\u4e00\u6027<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u901a\u8fc7compareTo()\uff08\u6216compare()\u5728\u4f7f\u7528\u6bd4\u8f83\u5668\u65f6\uff09\u65b9\u6cd5\u786e\u5b9a\u5143\u7d20\u7684\u552f\u4e00\u6027\u548c\u6392\u5e8f\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u6392\u5e8f<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u5143\u7d20\u4f1a\u6309\u7167\u81ea\u7136\u987a\u5e8f\uff08\u5373\u5b83\u4eec\u7684\u6bd4\u8f83\u987a\u5e8f\uff09\u6216\u8005\u6784\u9020\u96c6\u5408\u65f6\u6307\u5b9a\u7684Comparator\u8fdb\u884c\u6392\u5e8f\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u6027\u80fd<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u63d0\u4f9b\u4e86\u5bf9\u6570\u65f6\u95f4\u7684\u67e5\u627e\u548c\u63d2\u5165\u6027\u80fd\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u7a7a\u95f4\u6548\u7387<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a\u56e0\u4e3a\u9700\u8981\u5b58\u50a8\u6811\u8282\u70b9\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5982\u5de6\u53f3\u5b50\u8282\u70b9\u548c\u7236\u8282\u70b9\u7684\u5f15\u7528\uff0c\u6240\u4ee5\u5185\u5b58\u5360\u7528\u901a\u5e38\u6bd4HashSet\u9ad8\u3002<\/span><\/li>\n<li><strong><span style=\"font-size: 16px; letter-spacing: normal;\">\u793a\u4f8b<\/span><\/strong><span style=\"font-size: 16px; letter-spacing: normal;\">\uff1a<\/span><\/li>\n<\/ul>\n<section class=\"code-snippet__fix code-snippet__js\">\n<pre class=\"code-snippet__js\" data-lang=\"cs\"><code><span class=\"code-snippet_outer\">Set&lt;String&gt; treeSet = <span class=\"code-snippet__keyword\">new<\/span> TreeSet&lt;&gt;();<\/span><\/code><code><span class=\"code-snippet_outer\">\ntreeSet.<span class=\"code-snippet__keyword\">add<\/span>(<span class=\"code-snippet__string\">\"Banana\"<\/span>);<\/span><\/code><code><span class=\"code-snippet_outer\">\ntreeSet.<span class=\"code-snippet__keyword\">add<\/span>(<span class=\"code-snippet__string\">\"Apple\"<\/span>);<\/span><\/code><code><span class=\"code-snippet_outer\">\ntreeSet.<span class=\"code-snippet__keyword\">add<\/span>(<span class=\"code-snippet__string\">\"Cherry\"<\/span>);<\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\">\n\/\/ \u8fed\u4ee3\u987a\u5e8f\u5c06\u4f1a\u662f Apple -&gt; Banana -&gt; Cherry<\/span><\/span><\/code><\/pre>\n<\/section>\n<p style=\"margin-top: 24px; margin-bottom: 24px;\" data-v-md-line=\"48\"><strong><span style=\"font-size: 20px;\">\u603b\u7ed3\uff1a<\/span><\/strong><\/p>\n<ul class=\"list-paddingleft-1\" data-v-md-line=\"49\">\n<li><span style=\"font-size: 16px; letter-spacing: normal;\">HashSet\u662f\u6700\u5feb\u7684\uff0c\u4f46\u4e0d\u4fdd\u8bc1\u6709\u5e8f\uff1b<\/span><\/li>\n<li><span style=\"font-size: 16px; letter-spacing: normal;\">LinkedHashSet\u4fdd\u8bc1\u4e86\u5143\u7d20\u63d2\u5165\u987a\u5e8f\uff1b<\/span><\/li>\n<li><span style=\"font-size: 16px; letter-spacing: normal;\">TreeSet\u4fdd\u8bc1\u4e86\u5143\u7d20\u6392\u5e8f\u987a\u5e8f\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7\u6bd4\u8f83\u5668\u81ea\u5b9a\u4e49\u6392\u5e8f\uff0c\u4f46\u5728\u6027\u80fd\u4e0a\u4f1a\u6162\u4e8e\u524d\u4e24\u8005<\/span><span style=\"font-size: 16px; letter-spacing: normal;\">\u3002<\/span><\/li>\n<\/ul>\n<p style=\"display: none;\">\n<blockquote><p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7: \u4e92\u8054\u7f51\u9762\u8bd5\u5c0f\u5e2e\u624b<\/p><\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>HashSet\u3001LinkedHashSet\u548cTreeSet\u90fd\u662fJava\u96c6\u5408\u6846\u67b6\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u5e76\u4e14\u5b83\u4eec\u90fd\u5b9e\u73b0\u4e86Set\u63a5\u53e3\u3002\u4e0b\u9762\u8be6\u7ec6\u8bf4\u660e &#8230;<\/p>\n","protected":false},"author":1,"featured_media":4130,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[30],"tags":[],"class_list":["post-4133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-30"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/05\/20240524145413821-150x150.jpeg","content_first_image":null,"post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/05\/20240524145413821-300x128.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/05\/20240524145413821-1024x436.jpeg","post_frist_image":null,"post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/05\/20240524145413821-300x128.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/05\/20240524145413821-1024x436.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2024\/05\/20240524145413821.jpeg","post_all_images":[],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"\u9762\u8bd5","post_date":"2024-05-21","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":412,"next_post_id":4137,"next_post_title":"\u9762\u8bd5\u5b98\uff1a\u89e3\u91ca\u4fe1\u53f7\u91cf\uff08Semaphore\uff09\u4e0e\u4e92\u65a5\u91cf\uff08Mutex\uff09\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f","previous_post_id":4129,"previous_post_title":"\u9762\u8bd5\u5b98\uff1aJava \u4e2d\u63a5\u53e3\u548c\u62bd\u8c61\u7c7b\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/4133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=4133"}],"version-history":[{"count":2,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/4133\/revisions"}],"predecessor-version":[{"id":6473,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/4133\/revisions\/6473"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/4130"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=4133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=4133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=4133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}