{"id":68,"date":"2025-03-22T11:47:46","date_gmt":"2025-03-22T03:47:46","guid":{"rendered":"https:\/\/boyliang.com\/?p=68"},"modified":"2025-08-05T21:58:13","modified_gmt":"2025-08-05T13:58:13","slug":"java%e9%9b%86%e5%90%88","status":"publish","type":"post","link":"https:\/\/boyliang.com\/index.php\/2025\/03\/22\/java%e9%9b%86%e5%90%88\/","title":{"rendered":"Java\u96c6\u5408"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u6cdb\u578b\uff08Generic\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u57fa\u672c\u6982\u5ff5\uff1a<\/h3>\n\n\n\n<p>\u6570\u636e\u7c7b\u578b\u7684\u53c2\u6570\u5316\u3002\uff08\u628a\u7c7b\u578b\u5f53\u6210\u53c2\u6570\u4e00\u6837\u4f20\u9012\uff0c\u53ea\u80fd\u7528\u5f15\u7528\u7c7b\u578b\uff09<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.\u6cdb\u578b\u7684\u597d\u5904\uff1a<\/h3>\n\n\n\n<p>\uff081\uff09\u4ee3\u7801\u53ef\u8bfb\u6027\u66f4\u597d\uff08\u4e0d\u7528\u5f3a\u5236\u8f6c\u6362\uff09<\/p>\n\n\n\n<p>\uff082\uff09\u7a0b\u5e8f\u66f4\u52a0\u5b89\u5168\uff08\u53ea\u8981\u7f16\u8bd1\u65f6\u671f\u6ca1\u6709\u8b66\u544a\uff0c\u8fd0\u884c\u65f6\u671f\u5c31\u4e0d\u4f1a\u51fa\u73b0ClassCastException\u5f02\u5e38\uff09<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.\u7c7b\u578b\u64e6\u9664\uff1a<\/h3>\n\n\n\n<p>\u7f16\u7801\u65f6\u91c7\u7528\u6cdb\u578b\u5199\u7684\u7c7b\u578b\u53c2\u6570\uff0c\u7f16\u8bd1\u5668\u4f1a\u5728\u7f16\u8bd1\u65f6\u53bb\u6389\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.\u6cdb\u578b\u7c7b \uff1a<\/h3>\n\n\n\n<p>E\uff08\u5728\u5bb9\u5668\u4e2d\u4f7f\u7528\uff0c\u8868\u793a\u5bb9\u5668\u4e2d\u7684\u5143\u7d20\uff09\u3001<br>T\uff08\u8868\u793a\u666e\u901a\u7684JAVA\u7c7b\uff09\u3001<br>K\uff08\u8868\u793a\u952e\uff0c\u7c7b\u5982Map\u4e2d\u7684\u952eKey\uff09\u3001<br>V(\u8868\u793a\u503c)\u3001<br>N\uff08\u8868\u793a\u6570\u503c\u7c7b\u578b\uff09\u3001<br>\uff1f\uff08\u8868\u793a\u4e0d\u786e\u5b9a\u7684JAVA\u7c7b\u578b\uff09<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\uff0c\u6307\u5b9a\u6cdb\u578b\u5177\u4f53\u7c7b\u578b<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5.\u6cdb\u578b\u63a5\u53e3\uff1a<\/h3>\n\n\n\n<p>\u6cdb\u578b\u63a5\u53e3\u548c\u6cdb\u578b\u7c7b\u7684\u58f0\u660e\u65b9\u5f0f\u4e00\u81f4<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a\u5728\u5b9e\u73b0\u63a5\u53e3\u65f6\u53ef\u4ee5\u4f20\u9012\u5177\u4f53\u6570\u636e\u7c7b\u578b\u4e5f\u53ef\u4ee5\u4ecd\u7136\u4f7f\u7528\u6cdb\u578b\u4f5c\u4e3a\u6570\u636e\u7c7b\u578b<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.\u6cdb\u578b\u65b9\u6cd5\uff1a<\/h3>\n\n\n\n<p>\u8c03\u7528\u6cdb\u578b\u65b9\u6cd5\u65f6\uff0c\u4e0d\u9700\u8981\u50cf\u6cdb\u578b\u7c7b\u90a3\u6837\u544a\u8bc9\u7f16\u8bd1\u5668\u662f\u4ec0\u4e48\u7c7b\u578b\uff0c\u7f16\u8bd1\u5668\u53ef\u4ee5\u81ea\u52a8\u63a8\u65ad\u51fa\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>-\u975e\u9759\u6001\u65b9\u6cd5\uff1a\u53ef\u4ee5\u4f7f\u7528\u6cdb\u578b\u7c7b\u4e2d\u6240\u5b9a\u4e49\u7684\u6cdb\u578b\uff0c\u4e5f\u53ef\u4ee5\u5c06\u6cdb\u578b\u5b9a\u4e49\u5728\u65b9\u6cd5\u4e0a\u3002<br>-\u9759\u6001\u65b9\u6cd5\uff1a\u65e0\u6cd5\u8bbf\u95ee\u7c7b\u4e0a\u5b9a\u4e49\u7684\u6cdb\u578b\uff0c\u5fc5\u987b\u5c06\u6cdb\u578b\u5b9a\u4e49\u5728\u65b9\u6cd5\u4e0a\u3002<\/p>\n\n\n\n<p>\u6cdb\u578b\u65b9\u6cd5\u4e0e\u53ef\u53d8\u53c2\u6570\uff1a\u5728\u6cdb\u578b\u65b9\u6cd5\u4e2d\uff0c\u6cdb\u578b\u4e5f\u53ef\u4ee5\u5b9a\u4e49\u53ef\u53d8\u53c2\u6570\u7c7b\u578b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u8bed\u6cd5\u7ed3\u6784\uff1a\t\t\npublic &lt;\u6cdb\u578b\u6807\u8bc6\u7b26\u53f7> void showMsg(\u6cdb\u578b\u6807\u8bc6\u7b26\u53f7. . . agrs){}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7.\u6cdb\u578b\u4e2d\u7684\u901a\u914d\u7b26\uff1a<\/h3>\n\n\n\n<p>\u65e0\u754c\u901a\u914d\u7b26\uff1a\u5f53\u7c7b\u578b\u4e0d\u786e\u5b9a\u65f6\u53ef\u4ee5\u4f7f\u7528<\/p>\n\n\n\n<p>\u901a\u914d\u7b26\u7684\u4e0a\u4e0b\u9650\u5b9a\uff1a<br>-\u901a\u914d\u7b26\u7684\u4e0a\u9650\u9650\u5b9a\uff1a<br>\uff1f\u5b9e\u9645\u7c7b\u578b\u53ef\u4ee5\u662f\u4e0a\u9650\u9650\u5b9a\u4e2d\u6240\u7ea6\u5b9a\u7684\u7c7b\u578b\uff0c\u4e5f\u53ef\u4ee5\u662f\u7ea6\u5b9a\u7c7b\u578b\u7684\u5b50\u7c7b\u578b<br>-\u901a\u914d\u7b26\u7684\u4e0b\u9650\u9650\u5b9a<br>\uff1f\u5b9e\u9645\u7c7b\u578b\u53ef\u4ee5\u662f\u4e0b\u9650\u9650\u5b9a\u4e2d\u6240\u7ea6\u5b9a\u7684\u7c7b\u578b\uff0c\u4e5f\u53ef\u4ee5\u662f\u7ea6\u5b9a\u7c7b\u578b\u7684\u7236\u7c7b<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8.\u6cdb\u578b\u7684\u5c40\u9650\u6027\u548c\u5e38\u89c1\u9519\u8bef\uff1a<\/h3>\n\n\n\n<p>1\uff09\u5c40\u9650\u6027\uff1a\u6cdb\u578b\u4e3b\u8981\u7528\u4e8e\u7f16\u8bd1\u9636\u6bb5\uff0c\u7f16\u8bd1\u540e\u751f\u6210\u5b57\u8282\u7801class\u6587\u4ef6\u4e0d\u5305\u542b\u6cdb\u578b\u4e2d\u7684\u7c7b\u578b\u4fe1\u606f\u3002\u7c7b\u578b\u53c2\u6570\u5728\u7f16\u8bd1\u540e\u4f1a\u66ff\u6362\u6210Object,\u8fd0\u884c\u65f6\u865a\u62df\u673a\u5e76\u4e0d\u77e5\u9053\u6cdb\u578b\u3002<br>2\uff09\u5e38\u89c1\u9519\u8bef\uff1a \u57fa\u672c\u7c7b\u578b\u4e0d\u80fd\u7528\u4e8e\u6cdb\u578b,\u4e0d\u80fd\u901a\u8fc7\u7c7b\u578b\u53c2\u6570\u521b\u5efa\u5bf9\u8c61<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u5bb9\u5668\u4ecb\u7ecd<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u5bb9\u5668\u7b80\u4ecb\uff1a<\/h3>\n\n\n\n<p>\u57fa\u7840\u6570\u7ec4\u5e76\u4e0d\u80fd\u6ee1\u8db3\u6211\u4eec\u5bf9\u4e8e\u201c\u7ba1\u7406\u548c\u7ec4\u7ec7\u6570\u636e\u7684\u9700\u6c42\u201d\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4e00\u79cd\u66f4\u5f3a\u5927\u3001\u66f4\u7075\u6d3b\u3001\u5bb9\u91cf\u968f\u65f6\u53ef\u4ee5\u6269\u5bb9\u7684\u5bb9\u5668\u6765\u88c5\u8f7d\u6211\u4eec\u7684\u5bf9\u8c61\u3002\u8fd9\u5c31\u662f\u5bb9\u5668\u4e5f\u53eb\u96c6\u5408\uff08Collection\uff09\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.\u5bb9\u5668\u7ed3\u6784:<\/h3>\n\n\n\n<p>Collection(\u5355\u4f8b\u96c6\u5408)\uff0cMap(\u53cc\u4f8b\u96c6\u5408)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u5355\u4f8b\u96c6\u5408<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.Collection\u63a5\u53e3\uff1a<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">(1)\u63a5\u53e3\u4ecb\u7ecd<\/h4>\n\n\n\n<p>Collection\u8868\u793a\u4e00\u7ec4\u5bf9\u8c61\uff0c\u5b83\u662f\u96c6\u4e2d\u3001\u6536\u96c6\u7684\u610f\u601d\u3002Collection\u63a5\u53e3\u7684\u4e24\u4e2a\u5b50\u63a5\u53e3\u662fList\u3001set\u63a5\u53e3\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">(2)Collection\u63a5\u53e3\u4e2d\u5b9a\u4e49\u7684\u65b9\u6cd5:<\/h4>\n\n\n\n<p>-\u589e\u52a0\u5143\u7d20\u5230\u5bb9\u5668\u4e2d-\u4ece\u5bb9\u5668\u4e2d\u79fb\u9664\u5143\u7d20-\u5bb9\u5668\u4e2d\u662f\u5426\u5305\u542b\u5143\u7d20-\u5bb9\u5668\u4e2d\u5143\u7d20\u7684\u6570\u91cf<br>-\u5bb9\u5668\u662f\u5426\u4e3a\u7a7a-\u6e05\u7a7a\u5bb9\u5668\u4e2d\u6240\u6709\u7684\u5143\u7d20-\u83b7\u53d6\u8fed\u4ee3\u5668\uff0c\u7528\u4e8e\u904d\u5386\u6240\u6709\u7684\u5143\u7d20<br>-\u672c\u5bb9\u5668\u662f\u5426\u5305\u542bc\u5bb9\u5668\u4e2d\u7684\u6240\u6709\u5143\u7d20-\u5c06\u5bb9\u5668\u6240\u6709\u7684\u5143\u7d20\u52a0\u5165\u672c\u5bb9\u5668<br>-\u79fb\u9664\u672c\u5bb9\u5668\u548c\u5bb9\u5668c\u4e2d\u90fd\u5305\u542b\u7684\u5143\u7d20-\u53d6\u4ea4\u96c6\uff08\u4fdd\u7559\u4ea4\u96c6\uff09-\u8f6c\u5316\u6210Object\u6570\u7ec4<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.List\u63a5\u53e3<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">(1)List\u63a5\u53e3\u7279\u70b9:<\/h4>\n\n\n\n<p>\u6709\u5e8f\uff0c\u53ef\u91cd\u590d<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">(2)List\u63a5\u53e3\u5e38\u7528\u65b9\u6cd5\uff1a<\/h4>\n\n\n\n<p>-\u5728\u6307\u5b9a\u4f4d\u7f6e\u63d2\u5165\u5143\u7d20\uff0c\u4ee5\u524d\u5143\u7d20\u5168\u90e8\u540e\u79fb\u4e00\u4f4d<\/p>\n\n\n\n<p>-\u4fee\u6539\u6307\u5b9a\u4f4d\u7f6e\u7684\u5143\u7d20-\u8fd4\u56de\u6307\u5b9a\u4f4d\u7f6e\u7684\u5143\u7d20<br>-\u5220\u9664\u6307\u5b9a\u4f4d\u7f6e\u7684\u5143\u7d20\uff0c\u540e\u9762\u7684\u5143\u7d20\u5168\u90e8\u524d\u79fb\u4e00\u4f4d<\/p>\n\n\n\n<p>-\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5339\u914d\u5143\u7d20\u7684\u7d22\u5f15\uff0c\u5982\u679c\u6ca1\u6709\u8be5\u5143\u7d20\uff0c\u8fd4\u56de-1 <\/p>\n\n\n\n<p>-\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u5339\u914d\u5143\u7d20\u7684\u7d22\u5f15\uff0c\u5982\u679c\u6ca1\u6709\u8be5\u5143\u7d20\uff0c\u8fd4\u56de-1<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">1)ArrayList:<\/h5>\n\n\n\n<p>1.\u5e95\u5c42:\u662f\u4f7f\u7528\u6570\u7ec4\u6765\u5b58\u50a8\u5143\u7d20.<\/p>\n\n\n\n<p>2.\u7279\u70b9\uff1a\u67e5\u8be2\u6548\u7387\u9ad8\uff0c\u589e\u5220\u6548\u7387\u4f4e\uff0c\u7ebf\u7a0b\u4e0d\u5b89\u5168\u3002\u7d22\u5f15\u67e5\u627e\uff0c\u7d22\u5f15\u6dfb\u52a0\uff0c\u5e76\u96c6\uff0c<br>\u4ea4\u96c6\uff0c\u5dee\u96c6<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">2)Vector:<\/h5>\n\n\n\n<p>1.\u5e95\u5c42\uff1a\u662f\u6570\u7ec4\uff0c\u76f8\u5173\u65b9\u6cd5\u52a0\u4e86\u540c\u6b65\u68c0\u67e5\uff08synchronized\u540c\u6b65\u6807\u8bb0\uff09.<\/p>\n\n\n\n<p>2.\u7279\u70b9\uff1a\u7ebf\u7a0b\u5b89\u5168\uff0c\u6548\u7387\u4f4e\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">3)LinkedList:<\/h5>\n\n\n\n<p>1.\u5e95\u5c42\uff1a\u7528\u53cc\u94fe\u8868\u5b9e\u73b0\u7684\u5b58\u50a8\u3002<br>2.\u7279\u70b9\uff1a\u67e5\u8be2\u6548\u7387\u4f4e\uff0c\u589e\u5220\u6548\u7387\u9ad8\uff0c\u7ebf\u7a0b\u4e0d\u5b89\u5168<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">4)\u603b\u7ed3\uff1aLIst\u5b9e\u73b0\u7c7b\u7684\u9009\u7528\u89c4\u5219<\/h5>\n\n\n\n<p>\u9700\u8981\u7ebf\u7a0b\u5b89\u5168\u65f6\uff0c\u7528Vector<br>\u4e0d\u5b58\u5728\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u65f6\uff0c\u67e5\u8be2\u8f83\u591a\u7528ArrayList(\u4e00\u822c\u4f7f\u7528\u5b83)\uff0c\u589e\u52a0\u6216\u5220\u9664\u5143\u7d20\u8f83\u591a\u7528LinkedList.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.Set\u63a5\u53e3<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">(1)\u7279\u70b9\uff1a<\/h4>\n\n\n\n<p>\u65e0\u5e8f\uff0c\u4e0d\u53ef\u91cd\u590d\u4fee\u6539<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">(2)set\u63a5\u53e3\u7684\u5e38\u7528\u65b9\u6cd5:<\/h4>\n\n\n\n<p>\u56e0\u4e3aList\u4e0eCollection\u90fd\u7ee7\u627fCollection\u63a5\u53e3\uff0c\u4e14Set\u6ca1\u6709\u65b0\u589e\u65b9\u6cd5\uff0c\u5219\u4e0eList\u76f8\u540c<br>\u6ce8\u610f\uff1a\u5728set\u4e2d\u6ca1\u6709\u7d22\u5f15\uff0c\u6240\u4ee5\u67e5\u627e\u53ea\u80fd\u904d\u5386\u67e5\u627e\uff0c\u6ca1\u6709\u5bf9\u5e94\u7684get(int index)\u65b9\u6cd5<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">1\uff09HashSet\uff1a<\/h5>\n\n\n\n<p>1.\u5e95\u5c42\uff1a\u4f7f\u7528HashMap\u5b58\u50a8\u5143\u7d20<br>2.\u7279\u70b9\uff1aHashSet\u662f\u4e00\u4e2a\u4e0d\u4fdd\u8bc1\u5143\u7d20\u7684\u987a\u5e8f\u4e14\u6ca1\u6709\u91cd\u590d\u5143\u7d20\u7684\u96c6\u5408\uff0c\u662f\u7ebf\u7a0b\u5e76\u4e0d\u5b89\u5168\u7684\u3002HashSet\u5141\u8bb8\u6709null\u5143\u7d20<br>\u65e0\u5e8f\uff1a\u5728hashset\u4e2d\u5e95\u5c42\u4f7f\u7528\u7684hashmap\u5b58\u50a8\u5143\u7d20\u7684\u3002hashMap\u5e95\u5c42\u4f7f\u7528\u7684\u662f\u6570\u7ec4\u4e0e\u94fe\u8868\u5b9e\u73b0\u5143\u7d20\u7684\u5b58\u50a8\u3002\u5143\u7d20\u5728\u6570\u7ec4\u4e2d\u5b58\u653e\u65f6\uff0c\u5e76\u4e0d\u662f\u6709\u5e8f\u5b58\u653e\u7684\u4e5f\u4e0d\u662f\u968f\u673a\u5b58\u653e\u7684\uff0c\u800c\u662f\u5bf9\u5143\u7d20\u7684\u54c8\u5e0c\u503c\u8fdb\u884c\u8fd0\u7b97\u51b3\u5b9a\u5143\u7d20\u5728\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e\u3002<br>\u4e0d\u91cd\u590d\uff1a\u5f53\u4e24\u4e2a\u5143\u7d20\u7684\u54c8\u5e0c\u503c\u8fdb\u884c\u8ba1\u7b97\u5f97\u5230\u76f8\u540c\u7684\u5728\u6570\u7ec4\u4e2d\u7684\u4f4d\u7f6e\u65f6\uff0c\u4f1a\u8c03\u7528\u5143\u7d20\u7684equals()\u65b9\u6cd5\u5224\u65ad\u4e24\u4e2a\u5143\u7d20\u662f\u5426\u76f8\u540c\u3002\u5982\u679c\u5143\u7d20\u76f8\u540c\u5219\u4e0d\u4f1a\u6dfb\u52a0\u8be5\u5143\u7d20\uff0c\u5982\u679c\u4e0d\u76f8\u540c\u4f1a\u4f7f\u7528\u5355\u5411\u94fe\u8868\u4fdd\u5b58\u8be5\u5143\u7d20\u3002<br>3.\u81ea\u5b9a\u4e49\u5b58\u50a8\u5bf9\u8c61\uff08\u6211\u8bb0\u5f97\u662f\u5fc5\u987b\u5b9e\u73b0equls\u65b9\u6cd5\u4e0ehashCode\u65b9\u6cd5\uff09<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">2\uff09TreeSet\uff1a<\/h5>\n\n\n\n<p>1.\u5e95\u5c42\uff1a\u4f7f\u7528TreeMap\u5b58\u50a8\u5143\u7d20<br>2.\u7279\u70b9\uff1a\u53ef\u4ee5\u5bf9\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\u3002\uff08\u5e95\u5c42\u5b9e\u9645\u662f\u7528TreeMap\u5b9e\u73b0\u7684\uff0c\u5185\u90e8\u7ef4\u6301\u4e86\u4e00\u4e2a\u7b80\u5316\u7248\u7684TreeMap\uff0c\u901a\u8fc7key\u6765\u5b58\u50a8\u5143\u7d20\uff0cTreeSet\u5185\u90e8\u9700\u8981\u5bf9\u5b58\u50a8\u7684\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u7ed9\u5b9a\u6392\u5e8f\u89c4\u5219\u3002\uff09<br>\u6392\u5e8f \u89c4\u5219\u5b9e\u73b0\u65b9\u5f0f\uff1a-1\u901a\u8fc7\u5143\u7d20\u81ea\u8eab\u5b9e\u73b0\u6bd4\u8f83\u89c4\u5219<br>\u9700\u8981\u5b9e\u73b0Comparable\u63a5\u53e3\u4e2d\u7684compareTo\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u4e2d\u7528\u6765\u5b9a\u4e49\u6bd4\u8f83\u89c4\u5219\u3002TreeSet\u901a\u8fc7\u8c03\u7528\u8be5\u65b9\u6cd5\u6765\u5b8c\u6210\u5bf9\u5143\u7d20\u7684\u6392\u5e8f\u5904\u7406\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>                                 -2\u901a\u8fc7\u6bd4\u8f83\u5668\u6307\u5b9a\u6bd4\u8f83\u89c4\u5219\n                \u901a\u8fc7\u6bd4\u8f83\u5668\u5b9a\u4e49\u6bd4\u8f83\u89c4\u5219\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5355\u72ec\u521b\u5efa\u4e00\u4e2a\u6bd4\u8f83\u5668\u9700\u8981\u5b9e\u73b0Comparator\u63a5\u53e3\u4e2d\u7684compare\u65b9\u6cd5\u6765\u5b9a\u4e49\u6bd4\u8f83\u89c4\u5219\u3002\u5728\u5b9e\u4f8b\u5316TreeSet\u65f6\u5c06\u6bd4\u8f83\u5668\u5bf9\u8c61\u4ea4\u7ed9TreeSet\u6765\u5b8c\u6210\u5143\u7d20\u7684\u6392\u5e8f\u5904\u7406\u3002\u6b64\u65f6\u5143\u7d20\u81ea\u8eab\u5c31\u4e0d\u9700\u8981\u5b9e\u73b0\u6bd4\u8f83\u89c4\u5219\u4e86\u3002<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u53cc\u4f8b\u96c6\u5408<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u63a5\u53e3\u7684\u7279\u70b9:<\/h3>\n\n\n\n<p>\u5b58\u50a8\u7ed3\u6784\u4e3a\uff1aKey\u4e0eValue,\u4e00\u4e2a\u952e\u53ea\u80fd\u5bf9\u5e94\u4e00\u4e2a\u503c\uff0c\u503c\u53ef\u4ee5\u91cd\u590d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.Map\u63a5\u53e3\u4e2d\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/h3>\n\n\n\n<p>-\u628akey\u4e0evalue\u6dfb\u52a0\u5230Map\u96c6\u5408\u4e2d<\/p>\n\n\n\n<p>-\u4ece\u6307\u5b9aMap\u4e2d\u5c06\u6240\u6709\u6620\u5c04\u5173\u7cfb\u590d\u5236\u5230\u6b64Map\u4e2d<\/p>\n\n\n\n<p>-\u5220\u9664key\u5bf9\u5e94\u7684value-\u6839\u636e\u6307\u5b9a\u7684key\uff0c\u83b7\u53d6\u5bf9\u5e94\u7684value<\/p>\n\n\n\n<p>-\u5224\u65ad\u5bb9\u5668\u4e2d\u662f\u5426\u5305\u542b\u6307\u5b9a\u7684key<\/p>\n\n\n\n<p>-\u5224\u65ad\u5bb9\u5668\u4e2d\u662f\u5426\u5305\u542b\u6307\u5b9a\u7684value<\/p>\n\n\n\n<p>-\u83b7\u53d6Map\u96c6\u5408\u4e2d\u6240\u6709\u7684key\uff0c\u5b58\u50a8\u5230set\u96c6\u5408\u4e2d<\/p>\n\n\n\n<p>-\u8fd4\u56de\u4e00\u4e2aSet\u57fa\u4e8eMap.Entry\u7c7b\u578b\u5305\u542bMap\u4e2d\u6240\u6709\u6620\u5c04<\/p>\n\n\n\n<p>-\u5220\u9664Map\u4e2d\u6240\u6709\u7684\u6620\u5c04<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">1\uff09HashMap\u5bb9\u5668\u7684\u4f7f\u7528<\/h5>\n\n\n\n<p>1.\u91c7\u7528\u54c8\u5e0c\u7b97\u6cd5\u5b9e\u73b0\uff0c\u65f6Map\u63a5\u53e3\u6700\u5e38\u7528\u7684\u5b9e\u73b0\u7c7b\u3002<br>2.\u952e\u4e0d\u80fd\u91cd\u590d\uff1a\u7531\u4e8ehashMap\u5e95\u5c42\u91c7\u7528\u4e86\u54c8\u5e0c\u8868\u5b58\u50a8\u6570\u636e\uff0c\u6211\u4eec\u8981\u6c42\u952e\u4e0d\u80fd\u91cd\u590d\uff0c\u5982\u679c\u53d1\u751f\u91cd\u590d\uff0c\u65b0\u952e\u503c\u66ff\u6362\u6389\u65e7\u7684\u3002<br>3.\u67e5\u627e\uff0c\u5220\u9664\uff0c\u4fee\u6539\u65b9\u9762\u90fd\u6709\u975e\u5e38\u9ad8\u7684\u6548\u7387<br>4.HashTable\u7c7b\u548cHashMap\u7528\u6cd5\u51e0\u4e4e\u4e00\u6837\uff0c\u5e95\u5c42\u5b9e\u73b0\u51e0\u4e4e\u4e00\u6837\uff0c\u53ea\u4e0d\u8fc7HashTable\u7684\u65b9\u6cd5\u6dfb\u52a0\u4e86synchronized\u5173\u952e\u5b57\u786e\u4fdd\u7ebf\u7a0b\u540c\u6b65\u68c0\u67e5\uff0c\u6548\u7387\u8f83\u4f4e\u3002<br>\u533a\u522b\uff1ahashMap\u7ebf\u7a0b\u4e0d\u5b89\u5168\uff0c\u6548\u7387\u9ad8\u3002\u5141\u8bb8key\u6216value\u4e3anull<br>hashTable\u7ebf\u7a0b\u5b89\u5168\uff0c\u6548\u7387\u4f4e\u3002\u4e0d\u5141\u8bb8key\u6216value\u4e3anull<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">2)TreeMap\u5bb9\u5668\u4f7f\u7528<\/h5>\n\n\n\n<p>1.\u652f\u6301\u5bf9key\u7684\u6392\u5e8f\uff0ckey\u9700\u8981\u5b9e\u73b0\u6bd4\u8f83\u89c4\u5219<br>2.TreeMap\u662f\u53ef\u4ee5\u5bf9\u952e\u8fdb\u884c\u6392\u5e8f\u7684\u4e00\u79cd\u5bb9\u5668\uff0c\u5728\u9700\u8981\u5bf9\u952e\u6392\u5e8f\u65f6\u53ef\u9009\u7528treeMap\u3002\uff08treeMap\u5e95\u5c42\u662f\u57fa\u4e8e\u7ea2\u9ed1\u6811\u5b9e\u73b0\u7684\uff09<br>3.\u5728\u4f7f\u7528TreeMap\u65f6\u9700\u8981\u7ed9\u5b9a\u6392\u5e8f\u89c4\u5219:<br>          -1.\u5143\u7d20\u81ea\u8eab\u5b9e\u73b0\u6bd4\u8f83\u89c4\u5219 -2.\u901a\u8fc7\u6bd4\u8f83\u5668\u5b9e\u73b0\u6bd4\u8f83\u89c4\u5219<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001Iterator\u63a5\u53e3<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u4f5c\u7528\uff1a<\/h3>\n\n\n\n<p>\u5b9a\u4e49\u4e86\u5bf9\u5355\u4f8b\u96c6\u5408\u8fdb\u884c\u8fed\u4ee3\u7684\u6807\u51c6<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.Iterator\u8fed\u4ee3\u5668\u63a5\u53e3\u4ecb\u7ecd\uff1a<\/h3>\n\n\n\n<p>Collection\u63a5\u53e3\u7ee7\u627f\u4e86Iterable\u63a5\u53e3\uff0c\u5728\u8be5\u63a5\u53e3\u4e2d\u5305\u542b\u4e00\u4e2a\u540d\u4e3aiterator\u7684\u62bd\u8c61\u65b9\u6cd5\uff0c\u6240\u6709\u5b9e\u73b0\u4e86Collection\u63a5\u53e3\u7684\u5bb9\u5668\u7c7b\u5bf9\u8be5\u65b9\u6cd5\u505a\u4e86\u5177\u4f53\u5b9e\u73b0\u3002iterator\u65b9\u6cd5\u4f1a\u8fd4\u56de\u4e00\u4e2aIterator\u63a5\u53e3\u7c7b\u578b\u7684\u8fed\u4ee3\u5668\u5bf9\u8c61\uff0c\u5728\u8be5\u5bf9\u8c61\u4e2d\u5305\u542b\u4e09\u4e2a\u65b9\u6cd5\u7528\u4e8e\u5b9e\u73b0\u5bf9\u5355\u4f8b\u5bb9\u5668\u7684\u8fed\u4ee3\u5904\u7406<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.\u5de5\u4f5c\u539f\u7406\uff1a<\/h3>\n\n\n\n<p>\u53ef\u4ee5\u7406\u89e3\u4e3a\u6e38\u6807<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4.Iterator\u63a5\u53e3\u5b9a\u4e49\u7684\u4e09\u4e2a\u65b9\u6cd5\uff1a<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>boolean hasNext();\/\/\u5224\u65ad\u6e38\u6807\u5f53\u524d\u4f4d\u7f6e\u662f\u5426\u8fd8\u6709\u5143\u7d20\u6ca1\u6709\u88ab\u904d\u5386\uff1b\nObject next();\/\/\u8fd4\u56de\u6e38\u6807\u5f53\u524d\u4f4d\u7f6e\u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\u5e76\u5c06\u6e38\u6807\u79fb\u52a8\u5230\u4e0b\u4e00\u4e2a\u4f4d\u7f6e\uff1b\nvoid remove();\/\/\u5220\u9664\u6e38\u6807\u5f53\u524d\u4f4d\u7f6e\u7684\u5143\u7d20\uff0c\u5728\u6267\u884c\u5b8cnext\u540e\u8be5\u64cd\u4f5c\u53ea\u80fd\u6267\u884c\u4e00\u6b21\uff1b\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5.\u8fed\u4ee3\u5668\u4f7f\u7528\u65f6\u8981\u6ce8\u610f\uff1a<\/h3>\n\n\n\n<p>\uff081\uff09\u4e0d\u8981\u5728\u4e00\u6b21\u5faa\u73af\u4e2d\u591a\u6b21\u8c03\u7528next\u65b9\u6cd5<br>\uff082\uff09\u5982\u679c\u8981\u904d\u5386\u65f6\uff0c\u5220\u9664\u96c6\u5408\u4e2d\u7684\u5143\u7d20\uff0c\u5efa\u8bae\u4f7f\u7528 iterator.remove();<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001Collections\u5de5\u5177\u7c7b<\/h2>\n\n\n\n<p>\uff08\u64cd\u4f5c\u5bb9\u5668\u7684\u5de5\u5177\u7c7b\uff09java.utils.Collections\u63d0\u4f9b\u4e86\u5bf9Set\u3001List\u3001Map\u8fdb\u884c\u6392\u5e8f\u3001\u586b\u5145\u3001\u67e5\u627e\u5143\u7d20\u7684\u8f85\u52a9\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6cdb\u578b\uff08Generic\uff09 1.\u57fa\u672c\u6982\u5ff5\uff1a \u6570\u636e\u7c7b\u578b\u7684\u53c2\u6570\u5316\u3002\uff08\u628a\u7c7b\u578b\u5f53\u6210\u53c2\u6570\u4e00\u6837\u4f20\u9012\uff0c\u53ea\u80fd\u7528\u5f15\u7528\u7c7b\u578b\uff09 2. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-68","post","type-post","status-publish","format-standard","hentry","category-10"],"_links":{"self":[{"href":"https:\/\/boyliang.com\/index.php\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/boyliang.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boyliang.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boyliang.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boyliang.com\/index.php\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":1,"href":"https:\/\/boyliang.com\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":69,"href":"https:\/\/boyliang.com\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions\/69"}],"wp:attachment":[{"href":"https:\/\/boyliang.com\/index.php\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boyliang.com\/index.php\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boyliang.com\/index.php\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}