{"id":359,"date":"2015-04-18T20:51:18","date_gmt":"2015-04-18T12:51:18","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=359"},"modified":"2015-05-13T16:37:38","modified_gmt":"2015-05-13T08:37:38","slug":"java-%e5%ae%b9%e5%99%a8%ef%bc%9a%e8%ae%a4%e8%af%86%e5%ae%b9%e5%99%a8","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=359","title":{"rendered":"Java \u5bb9\u5668\uff1a\u8ba4\u8bc6\u5bb9\u5668"},"content":{"rendered":"<p>\u5bb9\u5668\u662fJava\u8bed\u8a00\u5b66\u4e60\u4e2d\u91cd\u8981\u7684\u4e00\u90e8\u5206\u3002\u6ce5\u74e6\u5320\u6211\u7684\u611f\u89c9\u662f\u521a\u5f00\u59cb\u633a\u96be\u5b66\u7684\uff0c\u4f46\u7b49\u4f60\u719f\u6089\u5b83\uff0c\u63a5\u89e6\u591a\u4e86\uff0c\u4e5f\u5c31\u201c\u987a\u7406\u6210\u7ae0\u201d\u5730\u77e5\u9053\u4e86\u3002Java\u7684\u5bb9\u5668\u7c7b\u4e3b\u8981\u7531\u4e24\u4e2a\u63a5\u53e3\u6d3e\u751f\u800c\u51fa\uff1a<strong>Collection\u548cMap<\/strong>\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u4e00\u3001Collection vs Collections<\/h2>\n<p>\u9996\u5148\uff0cCollection \u548c Collections \u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u6982\u5ff5\u3002\u4e4b\u6240\u4ee5\u653e\u5728\u4e00\u8d77\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u6bd4\u8f83\u3002<strong>Collection\u662f\u5bb9\u5668\u5c42\u6b21\u7ed3\u6784\u4e2d\u6839\u63a5\u53e3\u3002\u800cCollections\u662f\u4e00\u4e2a\u63d0\u4f9b\u4e00\u4e9b\u5904\u7406\u5bb9\u5668\u7c7b\u9759\u6001\u65b9\u6cd5\u7684\u7c7b\u3002<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>JDK\u4e0d\u63d0\u4f9bCollection\u63a5\u53e3\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u800c\u662f\u63d0\u4f9b\u4e86\u66f4\u52a0\u5177\u4f53\u7684\u5b50\u63a5\u53e3\uff08\u5982Set\u548cList\uff09\u5b9e\u73b0<\/strong>\u3002<\/p>\n<p>\u90a3Collection\u63a5\u53e3\u5b58\u5728\u6709\u4f55\u4f5c\u7528\u5462\uff1f\u5b58\u5728\u5373\u662f\u9053\u7406\u3002<\/p>\n<p>\u539f\u56e0\u5728\u4e8e\uff1a\u6240\u6709\u5bb9\u5668\u7684\u5b9e\u73b0\u7c7b\uff08\u5982ArrayList\u5b9e\u73b0\u4e86List\u63a5\u53e3\uff0cHashSet\u5b9e\u73b0\u4e86Set\u63a5\u53e3\uff09\u63d0\u4f9b\u4e86\u4e24\u4e2a\u2018\u6807\u51c6\u2019\u7684\u6784\u9020\u51fd\u6570\u6765\u5b9e\u73b0\uff1a1\u3001\u4e00\u4e2a\u65e0\u53c2\u7684\u6784\u9020\u65b9\u6cd5\uff08void\uff092\u3001\u4e00\u4e2a\u5e26\u6709<strong>Collection\u7c7b\u578b<\/strong>\u5355\u53c2\u6570\u6784\u9020\u65b9\u6cd5\uff0c\u7528\u4e8e\u521b\u5efa\u4e00\u4e2a\u5177\u6709\u5176\u53c2\u6570\u76f8\u540c\u5143\u7d20\u65b0\u7684Collection\u53ca\u5176\u5b9e\u73b0\u7c7b\u7b49\u3002<strong>\u5b9e\u9645\u4e0a<\/strong>\uff1a\u56e0\u4e3a\u6240\u6709\u901a\u7528\u7684\u5bb9\u5668\u7c7b\u9075\u4eceCollection\u63a5\u53e3\uff0c\u7528\u7b2c\u4e8c\u79cd\u6784\u9020\u65b9\u6cd5\u662f\u5141\u8bb8\u5bb9\u5668\u4e4b\u95f4\u76f8\u4e92\u7684\u590d\u5236\u3002<\/p>\n<h2>\u4e8c\u3001Collection\u7684\u7c7b\u5c42\u6b21\u7ed3\u6784<\/h2>\n<p>\u4e0b\u9762\u7684\u56fe\u662f\u5173\u4e8eCollection\u7684\u7c7b\u7684\u5c42\u6b21\u7ed3\u6784\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-363\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/04\/QQ\u255c\u256a\u2550\u255d20150418205948.png\" alt=\"QQ\u255c\u256a\u2550\u255d20150418205948\" width=\"531\" height=\"310\" \/><\/p>\n<p><strong>Set<\/strong>\uff1a<\/p>\n<p>\u4e00\u4e2a<strong>\u4e0d\u5305\u62ec\u91cd\u590d\u5143\u7d20\uff08\u5305\u62ec\u53ef\u53d8\u5bf9\u8c61\uff09<\/strong>\u7684Collection\uff0c\u662f\u4e00\u79cd<strong>\u65e0\u5e8f<\/strong>\u7684\u96c6\u5408\u3002Set\u4e0d\u5305\u542b\u6ee1 a.equals(b) \u7684\u5143\u7d20\u5bf9a\u548cb\uff0c\u5e76\u4e14\u6700\u591a\u6709\u4e00\u4e2anull\u3002\u5b9e\u73b0Set\u7684\u63a5\u53e3\u6709\uff1aEnumSet\u3001HashSet\u3001TreeSet\u7b49\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>List<\/strong>\uff1a<\/p>\n<p>\u4e00\u4e2a<strong>\u6709\u5e8f<\/strong>\u7684Collection\uff08\u4e5f\u79f0\u5e8f\u5217\uff09\uff0c\u5143\u7d20<strong>\u53ef\u4ee5\u91cd\u590d<\/strong>\u3002\u786e\u5207\u7684\u8bb2\uff0c\u5217\u8868\u901a\u5e38\u5141\u8bb8\u6ee1\u8db3\u00a0<tt>e1.equals(e2)<\/tt>\u00a0\u7684\u5143\u7d20\u5bf9\u00a0<tt>e1<\/tt>\u00a0\u548c\u00a0<tt>e2<\/tt>\uff0c\u5e76\u4e14\u5982\u679c\u5217\u8868\u672c\u8eab\u5141\u8bb8 null \u5143\u7d20\u7684\u8bdd\uff0c\u901a\u5e38\u5b83\u4eec\u5141\u8bb8\u591a\u4e2a null \u5143\u7d20\u3002\u5b9e\u73b0List\u7684\u6709\uff1aArrayList\u3001LinkedList\u3001Vector\u3001Stack\u7b49\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Queue<\/strong>\uff1a<\/p>\n<p>\u4e00\u79cd\u961f\u5217\u5219\u662f<strong>\u53cc\u7aef\u961f\u5217<\/strong>\uff0c\u652f\u6301\u5728\u5934\u3001\u5c3e\u4e24\u7aef\u63d2\u5165\u548c\u79fb\u9664\u5143\u7d20\uff0c\u4e3b\u8981\u5305\u62ec\uff1aArrayDeque\u3001LinkedBlockingDeque\u3001LinkedList\u3002\u53e6\u4e00\u79cd\u662f<strong>\u963b\u585e\u5f0f\u961f\u5217<\/strong>\uff0c\u961f\u5217\u6ee1\u4e86\u4ee5\u540e\u518d\u63d2\u5165\u5143\u7d20\u5219\u4f1a\u629b\u51fa\u5f02\u5e38\uff0c\u4e3b\u8981\u5305\u62ecArrayBlockQueue\u3001PriorityBlockingQueue\u3001LinkedBlockingQueue\u3002\u867d\u7136\u63a5\u53e3\u5e76\u672a\u5b9a\u4e49\u963b\u585e\u65b9\u6cd5\uff0c\u4f46\u662f\u5b9e\u73b0\u7c7b\u6269\u5c55\u4e86\u6b64\u63a5\u53e3\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u4e09\u3001Map\u7684\u7c7b\u7684\u5c42\u6b21\u7ed3\u6784<\/h2>\n<p>\u4e0b\u9762\u7684\u56fe\u662fMap\u7684\u5c42\u6b21\u7ed3\u6784\u56fe<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-364\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/04\/QQ\u255c\u256a\u2550\u255d20150418205934.png\" alt=\"QQ\u255c\u256a\u2550\u255d20150418205934\" width=\"519\" height=\"305\" \/><\/p>\n<p>Map\uff1a<\/p>\n<p>\u662f\u4e00\u4e2a\u952e\u503c\u5bf9\u7684\u96c6\u5408\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e00\u4e2a\u6620\u5c04\u4e0d\u80fd\u5305\u542b\u91cd\u590d\u7684\u952e\uff0c\u6bcf\u4e2a\u952e\u6700\u591a\u6620\u5c04\u5230\u4e00\u4e2a\u503c\u3002\u8be5\u63a5\u53e3\u53d6\u4ee3\u4e86Dictionary\u62bd\u8c61\u7c7b\u3002\u5b9e\u73b0map\u7684\u6709\uff1aHashMap\u3001TreeMap\u3001HashTable\u3001Properties\u3001EnumMap\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u56db\u3001\u5bb9\u5668\u63a5\u53e3\u7684\u5c0f\u7ed3<\/h2>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"http:\/\/www.programcreek.com\/wp-content\/uploads\/2009\/02\/collection-summary.png\" alt=\"collection-summary\" width=\"537\" height=\"158\" data-bd-imgshare-binded=\"1\" \/><\/p>\n<h2>\u4e94\u3001\u4ee3\u7801\u6837\u4f8b<\/h2>\n<p>\u5bf9HashMap\uff0cHashSet\uff0cLinkedList\uff0cArrayList\uff0cTreeMap\uff0cTreeSet\u7684\u4f8b\u5b50\u5982\u4e0b\uff1a<\/p>\n<p>[java]import java.util.ArrayList;<br \/>\nimport java.util.HashMap;<br \/>\nimport java.util.HashSet;<br \/>\nimport java.util.LinkedList;<br \/>\nimport java.util.List;<br \/>\nimport java.util.Map;<br \/>\nimport java.util.Set;<br \/>\nimport java.util.TreeMap;<br \/>\nimport java.util.TreeSet;<\/p>\n<p>@SuppressWarnings(&quot;unchecked&quot;)<br \/>\npublic class CollectionAll<br \/>\n{<\/p>\n<p>    public static void main(String[] args)<br \/>\n    {<br \/>\n        printLists();<\/p>\n<p>        printSets();<\/p>\n<p>        printMaps();<br \/>\n    }<\/p>\n<p>    private static void printLists()<br \/>\n    {<br \/>\n        List&lt;String&gt; a1 = new ArrayList&lt;String&gt;();<br \/>\n        a1.add(&quot;List&quot;);<br \/>\n        a1.add(&quot;Set&quot;);<br \/>\n        a1.add(&quot;Queue&quot;);<br \/>\n        a1.add(&quot;Map&quot;);<br \/>\n        System.out.println(&quot;ArrayList Elements:&quot;);<br \/>\n        System.out.print(&quot;\\t&quot; + a1 + &quot;\\n&quot;);<\/p>\n<p>        List&lt;String&gt; l1 = new LinkedList&lt;String&gt;();<br \/>\n        l1.add(&quot;List&quot;);<br \/>\n        l1.add(&quot;Set&quot;);<br \/>\n        l1.add(&quot;Queue&quot;);<br \/>\n        l1.add(&quot;Map&quot;);<br \/>\n        System.out.println(&quot;LinkedList Elements:&quot;);<br \/>\n        System.out.print(&quot;\\t&quot; + l1 + &quot;\\n&quot;);<br \/>\n    }<br \/>\n    @SuppressWarnings(&quot;rawtypes&quot;)<br \/>\n    private static void printSets()<br \/>\n    {<br \/>\n        Set h1 = new HashSet&lt;String&gt;();<br \/>\n        h1.add(&quot;List&quot;);<br \/>\n        h1.add(&quot;Set&quot;);<br \/>\n        h1.add(&quot;Queue&quot;);<br \/>\n        h1.add(&quot;Map&quot;);<br \/>\n        System.out.println(&quot;HashSet Elements:&quot;);<br \/>\n        System.out.print(&quot;\\t&quot; + h1 + &quot;\\n&quot;);<\/p>\n<p>        Set t1 = new TreeSet&lt;String&gt;();<br \/>\n        t1.add(&quot;List&quot;);<br \/>\n        t1.add(&quot;Set&quot;);<br \/>\n        t1.add(&quot;Queue&quot;);<br \/>\n        t1.add(&quot;Map&quot;);<br \/>\n        System.out.println(&quot;TreeSet Elements:&quot;);<br \/>\n        System.out.print(&quot;\\t&quot; + t1 + &quot;\\n&quot;);<br \/>\n    }<\/p>\n<p>    private static void printMaps()<br \/>\n    {<br \/>\n        Map&lt;String, String&gt; h1 = new HashMap&lt;String, String&gt;();<br \/>\n        h1.put(&quot;List&quot;, &quot;ArrayList&quot;);<br \/>\n        h1.put(&quot;Set&quot;, &quot;HashSet&quot;);<br \/>\n        h1.put(&quot;Queue&quot;, &quot;PriorityQueue&quot;);<br \/>\n        h1.put(&quot;Map&quot;, &quot;HashMap&quot;);<br \/>\n        System.out.println(&quot;HashMap Elements:&quot;);<br \/>\n        System.out.print(&quot;\\t&quot; + h1 + &quot;\\n&quot;);<\/p>\n<p>        Map&lt;String, String&gt; t1 = new TreeMap&lt;String,String&gt;();<br \/>\n        t1.put(&quot;List&quot;, &quot;ArrayList&quot;);<br \/>\n        t1.put(&quot;Set&quot;, &quot;HashSet&quot;);<br \/>\n        t1.put(&quot;Queue&quot;, &quot;PriorityQueue&quot;);<br \/>\n        t1.put(&quot;Map&quot;, &quot;HashMap&quot;);<br \/>\n        System.out.println(&quot;TreeMap Elements:&quot;);<br \/>\n        System.out.print(&quot;\\t&quot; + t1 + &quot;\\n&quot;);<\/p>\n<p>    }<br \/>\n}[\/java]<\/p>\n<p>\u63a7\u5236\u53f0\u6253\u5370\u5982\u4e0b\uff1a<\/p>\n<p>ArrayList Elements:<br \/>\n[List, Set, Queue, Map]<br \/>\nLinkedList Elements:<br \/>\n[List, Set, Queue, Map]<br \/>\nHashSet Elements:<br \/>\n[Map, Queue, Set, List]<br \/>\nTreeSet Elements:<br \/>\n[List, Map, Queue, Set]<br \/>\nHashMap Elements:<br \/>\n{Map=HashMap, Queue=PriorityQueue, Set=HashSet, List=ArrayList}<br \/>\nTreeMap Elements:<br \/>\n{List=ArrayList, Map=HashMap, Queue=PriorityQueue, Set=HashSet}<br \/>\n\u516d\u3001\u603b\u7ed3<br \/>\n\u5f02\u540c\u70b9<\/p>\n<p>\u51fa\u5904\uff1a<a class=\"external\" href=\"http:\/\/blog.csdn.net\/softwave\/article\/details\/4166598\" target=\"_blank\" rel=\"nofollow\">http:\/\/blog.csdn.net\/softwave\/article\/details\/4166598<\/a><\/p>\n<h5>Vector\u548cArrayList<\/h5>\n<p>1\uff0cvector\u662f\u7ebf\u7a0b\u540c\u6b65\u7684\uff0c\u6240\u4ee5\u5b83\u4e5f\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u800carraylist\u662f\u7ebf\u7a0b\u5f02\u6b65\u7684\uff0c\u662f\u4e0d\u5b89\u5168\u7684\u3002\u5982\u679c\u4e0d\u8003\u8651\u5230\u7ebf\u7a0b\u7684\u5b89\u5168\u56e0\u7d20\uff0c\u4e00\u822c\u7528arraylist\u6548\u7387\u6bd4\u8f83\u9ad8\u3002<br \/>\n2\uff0c\u5982\u679c\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u7684\u6570\u76ee\u5927\u4e8e\u76ee\u524d\u96c6\u5408\u6570\u7ec4\u7684\u957f\u5ea6\u65f6\uff0cvector\u589e\u957f\u7387\u4e3a\u76ee\u524d\u6570\u7ec4\u957f\u5ea6\u7684100%,\u800carraylist\u589e\u957f\u7387\u4e3a\u76ee\u524d\u6570\u7ec4\u957f\u5ea6\u768450%.\u5982\u8fc7\u5728\u96c6\u5408\u4e2d\u4f7f\u7528\u6570\u636e\u91cf\u6bd4\u8f83\u5927\u7684\u6570\u636e\uff0c\u7528vector\u6709\u4e00\u5b9a\u7684\u4f18\u52bf\u3002<br \/>\n3\uff0c\u5982\u679c\u67e5\u627e\u4e00\u4e2a\u6307\u5b9a\u4f4d\u7f6e\u7684\u6570\u636e\uff0cvector\u548carraylist\u4f7f\u7528\u7684\u65f6\u95f4\u662f\u76f8\u540c\u7684\uff0c\u90fd\u662f0(1),\u8fd9\u4e2a\u65f6\u5019\u4f7f\u7528vector\u548carraylist\u90fd\u53ef\u4ee5\u3002\u800c\u5982\u679c\u79fb\u52a8\u4e00\u4e2a\u6307\u5b9a\u4f4d\u7f6e\u7684\u6570\u636e\u82b1\u8d39\u7684\u65f6\u95f4\u4e3a0(n-i)n\u4e3a\u603b\u957f\u5ea6\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u5e94\u8be5\u8003\u8651\u5230\u4f7f\u7528linklist,\u56e0\u4e3a\u5b83\u79fb\u52a8\u4e00\u4e2a\u6307\u5b9a\u4f4d\u7f6e\u7684\u6570\u636e\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u4e3a0(1),\u800c\u67e5\u8be2\u4e00\u4e2a\u6307\u5b9a\u4f4d\u7f6e\u7684\u6570\u636e\u65f6\u82b1\u8d39\u7684\u65f6\u95f4\u4e3a0(i)\u3002<\/p>\n<p>ArrayList \u548cVector\u662f\u91c7\u7528\u6570\u7ec4\u65b9\u5f0f\u5b58\u50a8\u6570\u636e\uff0c\u6b64\u6570\u7ec4\u5143\u7d20\u6570\u5927\u4e8e\u5b9e\u9645\u5b58\u50a8\u7684\u6570\u636e\u4ee5\u4fbf\u589e\u52a0\u548c\u63d2\u5165\u5143\u7d20\uff0c\u90fd\u5141\u8bb8\u76f4\u63a5\u5e8f\u53f7\u7d22\u5f15\u5143\u7d20\uff0c\u4f46\u662f\u63d2\u5165\u6570\u636e\u8981\u8bbe\u8ba1\u5230\u6570\u7ec4\u5143\u7d20\u79fb\u52a8\u7b49\u5185\u5b58\u64cd\u4f5c\uff0c\u6240\u4ee5\u7d22\u5f15\u6570\u636e\u5feb\u63d2\u5165\u6570\u636e\u6162\uff0cVector\u7531\u4e8e\u4f7f\u7528\u4e86synchronized\u65b9\u6cd5\uff08\u7ebf\u7a0b\u5b89\u5168\uff09\u6240\u4ee5\u6027\u80fd\u4e0a\u6bd4ArrayList\u8981\u5dee\uff0cLinkedList\u4f7f\u7528\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u5b58\u50a8\uff0c\u6309\u5e8f\u53f7\u7d22\u5f15\u6570\u636e\u9700\u8981\u8fdb\u884c\u5411\u524d\u6216\u5411\u540e\u904d\u5386\uff0c\u4f46\u662f\u63d2\u5165\u6570\u636e\u65f6\u53ea\u9700\u8981\u8bb0\u5f55\u672c\u9879\u7684\u524d\u540e\u9879\u5373\u53ef\uff0c\u6240\u4ee5\u63d2\u5165\u6570\u5ea6\u8f83\u5feb\uff01<\/p>\n<h5><strong>Aarraylist\u548cLinkedlist<\/strong><\/h5>\n<p>1.ArrayList\u662f\u5b9e\u73b0\u4e86\u57fa\u4e8e\u52a8\u6001\u6570\u7ec4\u7684\u6570\u636e\u7ed3\u6784\uff0cLinkedList\u57fa\u4e8e\u94fe\u8868\u7684\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<p>2.\u5bf9\u4e8e\u968f\u673a\u8bbf\u95eeget\u548cset\uff0cArrayList\u89c9\u5f97\u4f18\u4e8eLinkedList\uff0c\u56e0\u4e3aLinkedList\u8981\u79fb\u52a8\u6307\u9488\u3002<\/p>\n<p>3.\u5bf9\u4e8e\u65b0\u589e\u548c\u5220\u9664\u64cd\u4f5cadd\u548cremove\uff0cLinedList\u6bd4\u8f83\u5360\u4f18\u52bf\uff0c\u56e0\u4e3aArrayList\u8981\u79fb\u52a8\u6570\u636e\u3002<\/p>\n<p>\u8fd9\u4e00\u70b9\u8981\u770b\u5b9e\u9645\u60c5\u51b5\u7684\u3002\u82e5\u53ea\u5bf9\u5355\u6761\u6570\u636e\u63d2\u5165\u6216\u5220\u9664\uff0cArrayList\u7684\u901f\u5ea6\u53cd\u800c\u4f18\u4e8eLinkedList\u3002\u4f46\u82e5\u662f\u6279\u91cf\u968f\u673a\u7684\u63d2\u5165\u5220\u9664\u6570\u636e\uff0cLinkedList\u7684\u901f\u5ea6\u5927\u5927\u4f18\u4e8eArrayList. \u56e0\u4e3aArrayList\u6bcf\u63d2\u5165\u4e00\u6761\u6570\u636e\uff0c\u8981\u79fb\u52a8\u63d2\u5165\u70b9\u53ca\u4e4b\u540e\u7684\u6240\u6709\u6570\u636e\u3002<\/p>\n<h5><strong>HashMap\u4e0eTreeMap<\/strong><\/h5>\n<p>1\u3001HashMap\u901a\u8fc7hashcode\u5bf9\u5176\u5185\u5bb9\u8fdb\u884c\u5feb\u901f\u67e5\u627e\uff0c\u800cTreeMap\u4e2d\u6240\u6709\u7684\u5143\u7d20\u90fd\u4fdd\u6301\u7740\u67d0\u79cd\u56fa\u5b9a\u7684\u987a\u5e8f\uff0c\u5982\u679c\u4f60\u9700\u8981\u5f97\u5230\u4e00\u4e2a\u6709\u5e8f\u7684\u7ed3\u679c\u4f60\u5c31\u5e94\u8be5\u4f7f\u7528TreeMap\uff08HashMap\u4e2d\u5143\u7d20\u7684\u6392\u5217\u987a\u5e8f\u662f\u4e0d\u56fa\u5b9a\u7684\uff09\u3002HashMap\u4e2d\u5143\u7d20\u7684\u6392\u5217\u987a\u5e8f\u662f\u4e0d\u56fa\u5b9a\u7684\uff09\u3002<\/p>\n<p>2\u3001\u00a0 HashMap\u901a\u8fc7hashcode\u5bf9\u5176\u5185\u5bb9\u8fdb\u884c\u5feb\u901f\u67e5\u627e\uff0c\u800cTreeMap\u4e2d\u6240\u6709\u7684\u5143\u7d20\u90fd\u4fdd\u6301\u7740\u67d0\u79cd\u56fa\u5b9a\u7684\u987a\u5e8f\uff0c\u5982\u679c\u4f60\u9700\u8981\u5f97\u5230\u4e00\u4e2a\u6709\u5e8f\u7684\u7ed3\u679c\u4f60\u5c31\u5e94\u8be5\u4f7f\u7528TreeMap\uff08HashMap\u4e2d\u5143\u7d20\u7684\u6392\u5217\u987a\u5e8f\u662f\u4e0d\u56fa\u5b9a\u7684\uff09\u3002\u96c6\u5408\u6846\u67b6\u201d\u63d0\u4f9b\u4e24\u79cd\u5e38\u89c4\u7684Map\u5b9e\u73b0\uff1aHashMap\u548cTreeMap (TreeMap\u5b9e\u73b0SortedMap\u63a5\u53e3)\u3002<\/p>\n<p>3\u3001\u5728Map \u4e2d\u63d2\u5165\u3001\u5220\u9664\u548c\u5b9a\u4f4d\u5143\u7d20\uff0cHashMap \u662f\u6700\u597d\u7684\u9009\u62e9\u3002\u4f46\u5982\u679c\u60a8\u8981\u6309\u81ea\u7136\u987a\u5e8f\u6216\u81ea\u5b9a\u4e49\u987a\u5e8f\u904d\u5386\u952e\uff0c\u90a3\u4e48TreeMap\u4f1a\u66f4\u597d\u3002\u4f7f\u7528HashMap\u8981\u6c42\u6dfb\u52a0\u7684\u952e\u7c7b\u660e\u786e\u5b9a\u4e49\u4e86hashCode()\u548c equals()\u7684\u5b9e\u73b0\u3002 \u8fd9\u4e2aTreeMap\u6ca1\u6709\u8c03\u4f18\u9009\u9879\uff0c\u56e0\u4e3a\u8be5\u6811\u603b\u5904\u4e8e\u5e73\u8861\u72b6\u6001\u3002<\/p>\n<h5><strong>hashtable\u4e0ehashmap<\/strong><\/h5>\n<p>1\u3001\u5386\u53f2\u539f\u56e0:Hashtable\u662f\u57fa\u4e8e\u9648\u65e7\u7684Dictionary\u7c7b\u7684\uff0cHashMap\u662fJava 1.2\u5f15\u8fdb\u7684Map\u63a5\u53e3\u7684\u4e00\u4e2a\u5b9e\u73b0 \u3002<\/p>\n<p>2\u3001\u540c\u6b65\u6027:Hashtable\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u662f\u540c\u6b65\u7684\uff0c\u800cHashMap\u662f\u7ebf\u7a0b\u5e8f\u4e0d\u5b89\u5168\u7684\uff0c\u4e0d\u662f\u540c\u6b65\u7684 \u3002<\/p>\n<p>3\u3001\u503c\uff1a\u53ea\u6709HashMap\u53ef\u4ee5\u8ba9\u4f60\u5c06\u7a7a\u503c\u4f5c\u4e3a\u4e00\u4e2a\u8868\u7684\u6761\u76ee\u7684key\u6216value \u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bb9\u5668\u662fJava\u8bed\u8a00\u5b66\u4e60\u4e2d\u91cd\u8981\u7684\u4e00\u90e8\u5206\u3002\u6ce5\u74e6\u5320\u6211\u7684\u611f\u89c9\u662f\u521a\u5f00\u59cb\u633a\u96be\u5b66\u7684\uff0c\u4f46\u7b49\u4f60\u719f\u6089\u5b83\uff0c\u63a5\u89e6\u591a\u4e86\uff0c\u4e5f\u5c31\u201c\u987a\u7406\u6210\u7ae0\u201d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/359"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=359"}],"version-history":[{"count":9,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/359\/revisions"}],"predecessor-version":[{"id":655,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/359\/revisions\/655"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}