{"id":124533,"date":"2026-11-19T03:56:35","date_gmt":"2026-11-18T19:56:35","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/124533.html"},"modified":"2026-11-19T03:56:35","modified_gmt":"2026-11-18T19:56:35","slug":"%e7%89%a2%e5%a4%a7%e5%b8%a6%e4%bd%a0%e5%ad%a6java%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84-%e4%b9%8blist","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/124533.html","title":{"rendered":"\u7262\u5927\u5e26\u4f60\u5b66java\u6570\u636e\u7ed3\u6784--\u4e4blist"},"content":{"rendered":"<p>        \/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/<br \/>\n        #content_views .toc,<br \/>\n        \/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/<br \/>\n        #content_views.markdown_views &gt; p:empty:has(+ .toc),<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty,<br \/>\n        \/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/<br \/>\n        #content_views.htmledit_views #main-toc,<br \/>\n        #content_views.htmledit_views #hr-toc,<br \/>\n        #content_views.htmledit_views p[id*=\\&#8221;-toc\\&#8221;] {<br \/>\n          display: none !important;<br \/>\n        }<br \/>\n        \/* \u76ee\u5f55\u53bb\u6389\u540e\uff0c\u7d27\u8ddf\u7684\u9996\u4e2a\u6807\u9898\u4e0d\u518d\u591a\u51fa\u4e00\u5757\u4e0a\u8fb9\u8ddd *\/<br \/>\n        #content_views.markdown_views &gt; .toc + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + h4,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h4 {<br \/>\n          margin-top: 0 !important;<br \/>\n        }<\/p>\n<h3>\u4e00\u3001\u5f15\u8a00&#xff1a;List \u63d0\u4f9b\u7684\u662f\u4e0b\u6807&#xff0c;\u5751\u4e5f\u957f\u5728\u4e0b\u6807\u4e0a<\/h3>\n<p>\u5199\u8d2d\u7269\u8f66\u7684\u65f6\u5019&#xff0c;\u6211\u4e00\u76f4\u4ee5\u4e3a\u81ea\u5df1\u7406\u89e3 List\u3002\u76f4\u5230\u6709\u4e00\u6b21\u8981 &#034;\u5220\u6389\u6570\u91cf\u4e3a 2 \u7684\u90a3\u4ef6\u5546\u54c1&#034;&#xff0c;\u5199\u4e86\u8fd9\u4e00\u884c&#xff1a;<\/p>\n<p>cart.remove(2);<\/p>\n<p>\u8fd0\u884c\u5b8c\u53d1\u73b0&#xff0c;\u6570\u91cf\u4e3a 2 \u7684\u90a3\u4ef6\u8fd8\u5728&#xff0c;\u7b2c 3 \u6761\u8bb0\u5f55\u6ca1\u4e86\u3002<\/p>\n<p>\u539f\u56e0\u4e0d\u590d\u6742&#xff1a;List \u91cc\u6709\u4e24\u4e2a remove&#xff0c;remove(int) \u5220\u7684\u662f\u4e0b\u6807&#xff0c;remove(Object) \u5220\u7684\u662f\u5bf9\u8c61\u30022 \u662f int \u5b57\u9762\u91cf&#xff0c;\u7f16\u8bd1\u5668\u9009\u4e86\u524d\u8005\u3002\u6211\u8111\u5b50\u91cc\u60f3\u7684\u662f &#034;\u503c 2&#034;&#xff0c;\u4ee3\u7801\u6267\u884c\u7684\u662f &#034;\u7b2c 2 \u4e2a\u4f4d\u7f6e&#034;\u3002<\/p>\n<p>\u540c\u6837\u7684\u4e8b\u540e\u6765\u53c8\u72af\u4e86\u4e00\u6b21&#xff1a;\u60f3\u53d6 &#034;\u524d\u4e24\u4ef6&#034; \u505a\u6ee1\u51cf&#xff0c;\u7528\u4e86 cart.subList(0, 2)&#xff0c;\u6539\u5b8c\u4ef7\u683c\u53d1\u73b0\u539f\u5217\u8868\u7684\u4ef7\u683c\u4e5f\u53d8\u4e86\u2014\u2014 \u56e0\u4e3a subList \u8fd4\u56de\u7684\u662f\u89c6\u56fe&#xff0c;\u4e0d\u662f\u62f7\u8d1d\u3002<\/p>\n<p>\u8fd9\u4e24\u4e2a bug \u6709\u4e00\u4e2a\u5171\u540c\u70b9&#xff1a;\u90fd\u51fa\u5728 &#034;\u4e0b\u6807&#034; \u4e0a\u3002<\/p>\n<p>List \u76f8\u5bf9 Collection \u591a\u51fa\u6765\u7684\u80fd\u529b&#xff0c;\u8bf4\u5230\u5e95\u53ea\u6709\u4e00\u4ef6\u4e8b&#xff1a;\u80fd\u6309\u4f4d\u7f6e\u8bbf\u95ee\u3002\u6709\u5e8f\u3001\u53ef\u91cd\u590d\u3001\u6709\u4e0b\u6807&#xff0c;\u4e09\u4e2a\u6027\u8d28\u7ed1\u5728\u4e00\u8d77\u3002\u800c\u4e00\u65e6\u6709\u4e86\u4e0b\u6807&#xff0c;\u5c31\u6709\u4e86\u4e09\u79cd\u6b67\u4e49&#xff1a;<\/p>\n<li>\u5220\u7684\u662f\u4f4d\u7f6e\u8fd8\u662f\u5bf9\u8c61\u2014\u2014remove \u7684\u91cd\u8f7d&#xff1b;<\/li>\n<li>\u62ff\u5230\u7684\u662f\u89c6\u56fe\u8fd8\u662f\u62f7\u8d1d\u2014\u2014subList&#xff1b;<\/li>\n<li>\u7ed3\u6784\u6539\u4e86\u4e4b\u540e&#xff0c;\u65e7\u5f15\u7528\u8fd8\u80fd\u4e0d\u80fd\u7528\u2014\u2014 \u904d\u5386\u4e2d\u589e\u5220\u4f1a\u629b ConcurrentModificationException\u3002<\/li>\n<p>\u8fd9\u7bc7\u6309\u8fd9\u4e09\u6761\u8d70\u3002<\/p>\n<p>\u73af\u5883\u8bf4\u660e&#xff1a;JDK 21 &#043; IntelliJ IDEA&#xff0c;\u5168\u90e8\u5728 java.util \u5305\u4e0b&#xff0c;\u793a\u4f8b\u5355\u6587\u4ef6\u53ef\u8fd0\u884c\u3002\u6587\u4e2d\u8f93\u51fa\u662f\u6309\u4ee3\u7801\u903b\u8f91\u80fd\u63a8\u51c6\u7684\u786e\u5b9a\u503c&#xff0c;\u4f46\u4ee3\u7801\u6ca1\u6709\u5728\u672c\u673a\u7f16\u8bd1\u8fd0\u884c\u8fc7&#xff08;\u5199\u6587\u7ae0\u8fd9\u53f0\u673a\u5668\u6ca1\u88c5 JDK&#xff09;\u3002<\/p>\n<h3>\u4e8c\u3001List \u5728\u96c6\u5408\u6846\u67b6\u91cc\u7684\u4f4d\u7f6e<\/h3>\n<h4>2.1 \u4e09\u5c42\u63a5\u53e3&#xff0c;\u5404\u7ba1\u4e00\u6bb5<\/h4>\n<p>Iterable -&gt; Collection -&gt; List<\/p>\n<ul>\n<li>Iterable&#xff1a;\u53ea\u627f\u8bfa\u4e00\u4ef6\u4e8b \u2014\u2014 \u80fd\u7528 for-each \u904d\u5386\u3002\u5b83\u63d0\u4f9b iterator()&#xff0c;for-each \u5c31\u662f\u9760\u8fd9\u4e2a\u65b9\u6cd5\u5de5\u4f5c\u7684&#xff1b;<\/li>\n<\/ul>\n<ul>\n<li>Collection&#xff1a;\u5355\u4e2a\u5143\u7d20\u7684\u96c6\u5408&#xff0c;\u7ba1 &#034;\u4e00\u5171\u6709\u51e0\u4e2a\u3001\u6709\u6ca1\u6709\u67d0\u4e2a\u5143\u7d20\u3001\u52a0\u4e00\u4e2a\u3001\u5220\u4e00\u4e2a\u3001\u6e05\u7a7a&#034;\u3002size()\u3001contains()\u3001add()\u3001remove()\u3001clear()\u3001toArray() \u90fd\u662f\u5b83\u5b9a\u7684&#xff1b;<\/li>\n<\/ul>\n<ul>\n<li>List&#xff1a;\u5728 Collection \u57fa\u7840\u4e0a\u52a0 &#034;\u4e0b\u6807&#034;\u2014\u2014get(int)\u3001set(int, E)\u3001add(int, E)\u3001remove(int)\u3001indexOf()\u3001lastIndexOf()\u3001subList()\u3001listIterator()\u3002<\/li>\n<\/ul>\n<p>\u6240\u4ee5\u5224\u65ad\u4e00\u4e2a\u65b9\u6cd5\u5c5e\u4e8e\u54ea\u4e00\u5c42&#xff0c;\u6709\u4e2a\u7b80\u5355\u7684\u529e\u6cd5&#xff1a;\u8ddf\u4f4d\u7f6e\u6709\u5173\u7684&#xff0c;\u90fd\u662f List \u52a0\u7684&#xff1b;\u8ddf &#034;\u6709\u6ca1\u6709\u3001\u6709\u51e0\u4e2a&#034; \u6709\u5173\u7684&#xff0c;\u662f Collection \u7684\u3002<\/p>\n<h4>2.2 List \u7684\u4e09\u6761\u6027\u8d28<\/h4>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<p>\u6027\u8d28<\/p>\n<\/td>\n<td>\n<p>\u542b\u4e49<\/p>\n<\/td>\n<td>\n<p>\u548c Set \u7684\u5dee\u522b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u6709\u5e8f<\/p>\n<\/td>\n<td>\n<p>\u6309\u63d2\u5165\u987a\u5e8f\u6392\u5217&#xff0c;\u4f4d\u7f6e\u4ece 0 \u5f00\u59cb<\/p>\n<\/td>\n<td>\n<p>HashSet \u4e0d\u4fdd\u8bc1\u987a\u5e8f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u53ef\u91cd\u590d<\/p>\n<\/td>\n<td>\n<p>\u540c\u4e00\u4e2a\u503c\u53ef\u4ee5\u51fa\u73b0\u591a\u6b21<\/p>\n<\/td>\n<td>\n<p>Set \u4e0d\u5141\u8bb8\u91cd\u590d<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u6709\u4e0b\u6807<\/p>\n<\/td>\n<td>\n<p>\u80fd get(i) \/ set(i, x)<\/p>\n<\/td>\n<td>\n<p>Set \u6ca1\u6709\u4e0b\u6807\u8bbf\u95ee<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd8\u6709\u4e00\u6761\u5bb9\u6613\u5ffd\u7565\u7684&#xff1a;\u591a\u6570 List \u5b9e\u73b0\u5141\u8bb8\u5b58 null&#xff08;ArrayList \u53ef\u4ee5&#xff09;&#xff0c;\u4f46 List.of(&#8230;) \u4e0d\u5141\u8bb8&#xff0c;\u4f20 null \u76f4\u63a5 NullPointerException\u3002\u63a5\u53e3\u672c\u8eab\u6ca1\u7981\u6b62&#xff0c;\u662f\u5b9e\u73b0\u51b3\u5b9a\u7684\u3002<\/p>\n<h4>2.3 \u63a5\u53e3\u4e0d\u80fd new<\/h4>\n<p>List&lt;String&gt; cart &#061; new List&lt;&gt;(); \/\/ \u7f16\u8bd1\u9519\u8bef&#xff1a;List \u662f\u63a5\u53e3<\/p>\n<p>List&lt;String&gt; cart &#061; new ArrayList&lt;&gt;(); \/\/ \u6b63\u786e&#xff1a;\u63a5\u53e3\u5f15\u7528 &#043; \u5b9e\u73b0\u7c7b\u5bf9\u8c61<\/p>\n<p>\u8fd9\u4e48\u5199\u4e0d\u662f\u7ed5\u8fdc\u8def&#xff0c;\u597d\u5904\u5f88\u5b9e\u5728&#xff1a;\u6362\u5b9e\u73b0\u7c7b\u53ea\u6539\u8fd9\u4e00\u884c&#xff0c;\u540e\u9762\u7684\u65b9\u6cd5\u8c03\u7528\u4e00\u884c\u90fd\u4e0d\u7528\u52a8\u3002\u4eca\u5929\u7528 ArrayList&#xff0c;\u54ea\u5929\u53d1\u73b0 &#034;\u5934\u90e8\u9891\u7e41\u63d2\u5165&#034; \u6210\u4e86\u74f6\u9888&#xff0c;\u6362\u6210 LinkedList&#xff0c;\u8c03\u7528\u65b9\u5b8c\u5168\u65e0\u611f\u3002<\/p>\n<p>\u5b9e\u73b0 List \u7684\u7c7b\u4e0d\u6b62\u4e24\u4e2a&#xff08;\u8fd8\u6709 Vector\u3001CopyOnWriteArrayList \u7b49&#xff09;&#xff0c;\u65e5\u5e38\u7528\u5f97\u591a\u7684\u662f ArrayList \u548c LinkedList&#xff0c;\u5b83\u4eec\u7684\u5dee\u522b\u653e\u5728\u7b2c\u516d\u8282\u3002<\/p>\n<h3>\u4e09\u3001\u5e38\u7528\u65b9\u6cd5&#xff1a;\u6309\u52a8\u4f5c\u5206\u7c7b<\/h3>\n<h4>3.1 \u589e&#xff1a;\u4e24\u4e2a add \u8fd4\u56de\u503c\u4e0d\u4e00\u6837<\/h4>\n<p>list.add(&#034;\u82f9\u679c&#034;); \/\/ \u5c3e\u63d2&#xff0c;\u8fd4\u56de boolean<\/p>\n<p>list.add(1, &#034;\u897f\u74dc&#034;); \/\/ \u63d2\u5230\u4e0b\u6807 1&#xff0c;\u8fd4\u56de void<\/p>\n<ul>\n<li>add(E e) \u8fd4\u56de boolean\u3002\u5bf9\u53ef\u53d8 List \u6765\u8bf4\u5b83\u6052\u4e3a true\u2014\u2014 \u63a5\u53e3\u8fd9\u4e48\u8bbe\u8ba1\u662f\u4e3a\u4e86\u517c\u5bb9 Set&#xff08;Set.add \u9047\u5230\u91cd\u590d\u4f1a\u8fd4\u56de false&#xff09;&#xff1b;<\/li>\n<\/ul>\n<ul>\n<li>add(int index, E element) \u8fd4\u56de void&#xff0c;\u56e0\u4e3a\u5b83\u4e00\u5b9a\u4f1a\u6210\u529f&#xff08;\u9664\u975e\u4e0b\u6807\u8d8a\u754c&#xff0c;\u90a3\u4f1a\u629b IndexOutOfBoundsException&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u4e0b\u6807\u53ef\u4ee5\u53d6 0 \u5230 size()&#xff08;\u6ce8\u610f&#xff1a;\u63d2\u5165\u65f6\u5141\u8bb8\u7b49\u4e8e size()&#xff0c;\u7b49\u4e8e\u5c3e\u63d2&#xff1b;get \/ set \u53ea\u5141\u8bb8\u5230 size()-1&#xff09;\u3002<\/p>\n<h4>3.2 \u5220&#xff1a;remove \u7684\u91cd\u8f7d\u662f\u4e2a\u771f\u5751<\/h4>\n<p>\/\/ \u6587\u4ef6&#xff1a;RemoveTrapDemo.java<br \/>\nimport java.util.ArrayList;<br \/>\nimport java.util.List;<\/p>\n<p>public class RemoveTrapDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/ \u573a\u666f\u4e00&#xff1a;\u6309\u4e0b\u6807\u5220<br \/>\n        List&lt;Integer&gt; numbers &#061; new ArrayList&lt;&gt;();<br \/>\n        numbers.add(10);<br \/>\n        numbers.add(20);<br \/>\n        numbers.add(30);<br \/>\n        Integer removed &#061; numbers.remove(1); \/\/ \u9009\u4e2d\u7684\u662f remove(int index)<br \/>\n        System.out.println(&#034;\u6309\u4e0b\u6807\u5220&#xff0c;\u8fd4\u56de\u88ab\u5220\u5143\u7d20&#xff1a;&#034; &#043; removed &#043; &#034;&#xff0c;\u5269\u4f59&#xff1a;&#034; &#043; numbers);<\/p>\n<p>        \/\/ \u573a\u666f\u4e8c&#xff1a;\u6309\u5bf9\u8c61\u5220<br \/>\n        List&lt;Integer&gt; numbers2 &#061; new ArrayList&lt;&gt;();<br \/>\n        numbers2.add(10);<br \/>\n        numbers2.add(20);<br \/>\n        numbers2.add(30);<br \/>\n        boolean ok &#061; numbers2.remove(Integer.valueOf(20)); \/\/ \u9009\u4e2d\u7684\u662f remove(Object)<br \/>\n        System.out.println(&#034;\u6309\u5bf9\u8c61\u5220&#xff0c;\u8fd4\u56de\u662f\u5426\u5220\u6389&#xff1a;&#034; &#043; ok &#043; &#034;&#xff0c;\u5269\u4f59&#xff1a;&#034; &#043; numbers2);<\/p>\n<p>        \/\/ \u573a\u666f\u4e09&#xff1a;\u76f4\u63a5\u5199 remove(20)&#xff0c;\u4f1a\u88ab\u5f53\u6210\u4e0b\u6807<br \/>\n        List&lt;Integer&gt; numbers3 &#061; new ArrayList&lt;&gt;();<br \/>\n        numbers3.add(10);<br \/>\n        numbers3.add(20);<br \/>\n        numbers3.add(30);<br \/>\n        try {<br \/>\n            numbers3.remove(20); \/\/ 20 \u5f53\u4e0b\u6807\u7528&#xff0c;\u8d8a\u754c<br \/>\n        } catch (IndexOutOfBoundsException ex) {<br \/>\n            System.out.println(&#034;remove(20) \u62a5\u9519&#xff1a;&#034; &#043; ex.getClass().getSimpleName());<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>\u6309\u4e0b\u6807\u5220&#xff0c;\u8fd4\u56de\u88ab\u5220\u5143\u7d20&#xff1a;20&#xff0c;\u5269\u4f59&#xff1a;[10, 30]<br \/>\n\u6309\u5bf9\u8c61\u5220&#xff0c;\u8fd4\u56de\u662f\u5426\u5220\u6389&#xff1a;true&#xff0c;\u5269\u4f59&#xff1a;[10, 30]<br \/>\nremove(20) \u62a5\u9519&#xff1a;IndexOutOfBoundsException<\/p>\n<p>\u5173\u952e\u5728\u7f16\u8bd1\u5668\u600e\u4e48\u9009\u91cd\u8f7d&#xff0c;\u89c4\u5219\u662f\u6309\u53c2\u6570\u7684\u9759\u6001\u7c7b\u578b&#xff0c;\u4e0d\u6309\u4f60\u8111\u5b50\u91cc\u7684\u610f\u56fe&#xff1a;<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<p>\u5199\u6cd5<\/p>\n<\/td>\n<td>\n<p>\u53c2\u6570\u7c7b\u578b<\/p>\n<\/td>\n<td>\n<p>\u9009\u4e2d\u65b9\u6cd5<\/p>\n<\/td>\n<td>\n<p>\u6548\u679c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>list.remove(1)<\/p>\n<\/td>\n<td>\n<p>int \u5b57\u9762\u91cf<\/p>\n<\/td>\n<td>\n<p>remove(int)<\/p>\n<\/td>\n<td>\n<p>\u5220\u4e0b\u6807 1&#xff0c;\u8fd4\u56de\u5143\u7d20<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>list.remove(Integer.valueOf(1))<\/p>\n<\/td>\n<td>\n<p>Integer<\/p>\n<\/td>\n<td>\n<p>remove(Object)<\/p>\n<\/td>\n<td>\n<p>\u5220\u7b2c\u4e00\u4e2a\u7b49\u4e8e 1 \u7684\u5143\u7d20&#xff0c;\u8fd4\u56de\u5e03\u5c14<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>list.remove((Object) 1)<\/p>\n<\/td>\n<td>\n<p>Object<\/p>\n<\/td>\n<td>\n<p>remove(Object)<\/p>\n<\/td>\n<td>\n<p>\u540c\u4e0a<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>list.remove(null)<\/p>\n<\/td>\n<td>\n<p>null<\/p>\n<\/td>\n<td>\n<p>remove(Object)<\/p>\n<\/td>\n<td>\n<p>\u5220\u7b2c\u4e00\u4e2a null<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6240\u4ee5 List&lt;Integer&gt; \u91cc\u60f3 &#034;\u6309\u503c\u5220&#034;&#xff0c;\u5fc5\u987b\u663e\u5f0f\u88c5\u7bb1&#xff08;remove(Integer.valueOf(x))&#xff09;\u3002List&lt;String&gt;\u3001List&lt;Item&gt; \u8fd9\u7c7b\u4e0d\u4f1a\u6709\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u56e0\u4e3a\u5143\u7d20\u4e0d\u662f int&#xff0c;remove(o) \u53ea\u4f1a\u5339\u914d remove(Object)\u3002<\/p>\n<p>\u987a\u5e26\u8bb0\u4e00\u4e0b\u8fd4\u56de\u503c&#xff1a;remove(int) \u8fd4\u56de\u88ab\u5220\u6389\u7684\u90a3\u4e2a\u5143\u7d20&#xff0c;remove(Object) \u8fd4\u56de\u6709\u6ca1\u6709\u5220\u6210\u529f\u3002\u8fd9\u4e24\u4e2a\u8fd4\u56de\u503c\u7c7b\u578b\u4e0d\u540c&#xff0c;\u662f\u91cd\u8f7d\u8bbe\u8ba1\u7559\u4e0b\u7684\u5386\u53f2\u75d5\u8ff9\u3002<\/p>\n<h4>3.3 \u67e5\u4e0e\u6539&#xff1a;set \u4f1a\u8fd4\u56de\u65e7\u503c<\/h4>\n<p>\/\/ \u6587\u4ef6&#xff1a;ListBasicsDemo.java<br \/>\nimport java.util.ArrayList;<br \/>\nimport java.util.List;<\/p>\n<p>public class ListBasicsDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        List&lt;String&gt; cart &#061; new ArrayList&lt;&gt;();<br \/>\n        cart.add(&#034;\u82f9\u679c&#034;); \/\/ \u5c3e\u63d2<br \/>\n        cart.add(&#034;\u9999\u8549&#034;);<br \/>\n        cart.add(&#034;\u6a59\u5b50&#034;);<br \/>\n        System.out.println(&#034;\u63d2\u5165\u524d&#xff1a;&#034; &#043; cart);<\/p>\n<p>        cart.add(1, &#034;\u897f\u74dc&#034;); \/\/ \u63d2\u5230\u4e0b\u6807 1&#xff0c;\u540e\u9762\u7684\u5143\u7d20\u6574\u4f53\u540e\u79fb<br \/>\n        System.out.println(&#034;\u63d2\u5230\u4e0b\u6807 1 \u540e&#xff1a;&#034; &#043; cart &#043; &#034;&#xff0c;\u5927\u5c0f&#xff1a;&#034; &#043; cart.size());<\/p>\n<p>        System.out.println(&#034;get(1)&#xff1a;&#034; &#043; cart.get(1));<\/p>\n<p>        String old &#061; cart.set(0, &#034;\u8461\u8404&#034;); \/\/ \u8986\u76d6\u4e0b\u6807 0&#xff0c;\u8fd4\u56de\u88ab\u8986\u76d6\u7684\u65e7\u503c<br \/>\n        System.out.println(&#034;set \u8fd4\u56de\u65e7\u503c&#xff1a;&#034; &#043; old &#043; &#034;&#xff0c;\u6539\u5b8c&#xff1a;&#034; &#043; cart);<\/p>\n<p>        cart.add(&#034;\u8461\u8404&#034;); \/\/ \u518d\u6765\u4e00\u4e2a\u540c\u540d\u5143\u7d20<br \/>\n        System.out.println(&#034;\u52a0\u4e00\u4e2a\u540c\u540d\u5143\u7d20\u540e&#xff1a;&#034; &#043; cart);<br \/>\n        System.out.println(&#034;indexOf(\u8461\u8404)&#xff1a;&#034; &#043; cart.indexOf(&#034;\u8461\u8404&#034;));<br \/>\n        System.out.println(&#034;lastIndexOf(\u8461\u8404)&#xff1a;&#034; &#043; cart.lastIndexOf(&#034;\u8461\u8404&#034;));<br \/>\n        System.out.println(&#034;contains(\u6a59\u5b50)&#xff1a;&#034; &#043; cart.contains(&#034;\u6a59\u5b50&#034;));<\/p>\n<p>        List&lt;String&gt; firstTwo &#061; cart.subList(0, 2); \/\/ \u5de6\u95ed\u53f3\u5f00&#xff1a;[0, 2)<br \/>\n        System.out.println(&#034;subList(0, 2)&#xff1a;&#034; &#043; firstTwo);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>\u63d2\u5165\u524d&#xff1a;[\u82f9\u679c, \u9999\u8549, \u6a59\u5b50]<br \/>\n\u63d2\u5230\u4e0b\u6807 1 \u540e&#xff1a;[\u82f9\u679c, \u897f\u74dc, \u9999\u8549, \u6a59\u5b50]&#xff0c;\u5927\u5c0f&#xff1a;4<br \/>\nget(1)&#xff1a;\u897f\u74dc<br \/>\nset \u8fd4\u56de\u65e7\u503c&#xff1a;\u82f9\u679c&#xff0c;\u6539\u5b8c&#xff1a;[\u8461\u8404, \u897f\u74dc, \u9999\u8549, \u6a59\u5b50]<br \/>\n\u52a0\u4e00\u4e2a\u540c\u540d\u5143\u7d20\u540e&#xff1a;[\u8461\u8404, \u897f\u74dc, \u9999\u8549, \u6a59\u5b50, \u8461\u8404]<br \/>\nindexOf(\u8461\u8404)&#xff1a;0<br \/>\nlastIndexOf(\u8461\u8404)&#xff1a;4<br \/>\ncontains(\u6a59\u5b50)&#xff1a;true<br \/>\nsubList(0, 2)&#xff1a;[\u8461\u8404, \u897f\u74dc]<\/p>\n<p>\u4e09\u70b9\u503c\u5f97\u8bb0&#xff1a;<\/p>\n<ul>\n<li>set \u8fd4\u56de\u65e7\u503c&#xff0c;\u8fd9\u4e2a\u8fd4\u56de\u503c\u4e0d\u662f\u6ca1\u7528\u7684&#xff1a;\u505a\u64a4\u9500\u65f6\u6b63\u597d\u62ff\u5b83\u56de\u6eda&#xff1b;<\/li>\n<li>indexOf \u4ece\u524d\u5f80\u540e\u627e\u7b2c\u4e00\u4e2a&#xff0c;lastIndexOf \u4ece\u540e\u5f80\u524d\u627e&#xff0c;\u627e\u4e0d\u5230\u90fd\u8fd4\u56de -1&#xff1b;<\/li>\n<li>subList(from, to) \u662f\u5de6\u95ed\u53f3\u5f00&#xff0c;subList(0, 2) \u53d6\u4e0b\u6807 0\u30011 \u4e24\u4e2a\u5143\u7d20&#xff0c;\u4e0d\u5305\u542b 2\u3002<\/li>\n<\/ul>\n<p>add(int, E) \u6709\u4e00\u4e2a\u4ee3\u4ef7&#xff1a;\u540e\u9762\u7684\u5143\u7d20\u8981\u6574\u4f53\u540e\u79fb\u4e00\u4f4d\u3002\u8fd9\u662f\u6570\u7ec4\u7ed3\u6784\u7684\u5fc5\u7136\u7ed3\u679c&#xff0c;\u63d2\u5165\u4f4d\u7f6e\u8d8a\u9760\u524d&#xff0c;\u4ee3\u4ef7\u8d8a\u5927\u3002<\/p>\n<h4>3.4 \u904d\u5386\u4e2d\u5220\u9664&#xff1a;for-each \u4f1a\u70b8<\/h4>\n<p>\/\/ \u6587\u4ef6&#xff1a;IteratorRemoveDemo.java<br \/>\nimport java.util.ArrayList;<br \/>\nimport java.util.ConcurrentModificationException;<br \/>\nimport java.util.Iterator;<br \/>\nimport java.util.List;<\/p>\n<p>public class IteratorRemoveDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/ \u9519\u8bef\u793a\u8303&#xff1a;for-each \u91cc\u76f4\u63a5\u5220<br \/>\n        List&lt;String&gt; names &#061; new ArrayList&lt;&gt;(List.of(&#034;\u5f20\u4e09&#034;, &#034;\u674e\u56db&#034;, &#034;\u738b\u4e94&#034;, &#034;\u8d75\u516d&#034;));<br \/>\n        try {<br \/>\n            for (String name : names) {<br \/>\n                if (name.equals(&#034;\u674e\u56db&#034;)) {<br \/>\n                    names.remove(name);<br \/>\n                }<br \/>\n            }<br \/>\n        } catch (ConcurrentModificationException ex) {<br \/>\n            System.out.println(&#034;for-each \u91cc\u5220\u9664&#xff1a;&#034; &#043; ex.getClass().getSimpleName());<br \/>\n        }<br \/>\n        System.out.println(&#034;\u5f02\u5e38\u540e\u5217\u8868&#xff1a;&#034; &#043; names);<\/p>\n<p>        \/\/ \u6b63\u786e\u793a\u8303\u4e00&#xff1a;\u8fed\u4ee3\u5668\u81ea\u5df1\u7684 remove<br \/>\n        List&lt;String&gt; names2 &#061; new ArrayList&lt;&gt;(List.of(&#034;\u5f20\u4e09&#034;, &#034;\u674e\u56db&#034;, &#034;\u738b\u4e94&#034;, &#034;\u8d75\u516d&#034;));<br \/>\n        Iterator&lt;String&gt; it &#061; names2.iterator();<br \/>\n        while (it.hasNext()) {<br \/>\n            String name &#061; it.next();<br \/>\n            if (name.equals(&#034;\u674e\u56db&#034;)) {<br \/>\n                it.remove();<br \/>\n            }<br \/>\n        }<br \/>\n        System.out.println(&#034;\u8fed\u4ee3\u5668\u5220\u9664\u540e&#xff1a;&#034; &#043; names2);<\/p>\n<p>        \/\/ \u6b63\u786e\u793a\u8303\u4e8c&#xff1a;removeIf&#xff08;JDK 8 \u8d77&#xff09;<br \/>\n        names2.removeIf(name -&gt; name.startsWith(&#034;\u8d75&#034;));<br \/>\n        System.out.println(&#034;removeIf \u4e4b\u540e&#xff1a;&#034; &#043; names2);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>for-each \u91cc\u5220\u9664&#xff1a;ConcurrentModificationException<br \/>\n\u5f02\u5e38\u540e\u5217\u8868&#xff1a;[\u5f20\u4e09, \u738b\u4e94, \u8d75\u516d]<br \/>\n\u8fed\u4ee3\u5668\u5220\u9664\u540e&#xff1a;[\u5f20\u4e09, \u738b\u4e94, \u8d75\u516d]<br \/>\nremoveIf \u4e4b\u540e&#xff1a;[\u5f20\u4e09, \u738b\u4e94]<\/p>\n<p>\u4e24\u4e2a\u7ec6\u8282&#xff1a;<\/p>\n<li>\u629b\u5f02\u5e38\u4e4b\u524d&#xff0c;\u5220\u9664\u5176\u5b9e\u5df2\u7ecf\u751f\u6548\u4e86\u3002\u6240\u4ee5 \u5f02\u5e38\u540e\u5217\u8868 \u91cc\u5df2\u7ecf\u6ca1\u6709 &#034;\u674e\u56db&#034;&#xff0c;\u4f46\u8fed\u4ee3\u5668\u5df2\u7ecf\u5e9f\u4e86&#xff0c;\u5269\u4e0b\u7684\u5143\u7d20\u6ca1\u904d\u5386\u5230 \u2014\u2014 \u8fd9\u7c7b &#034;\u4e00\u534a\u6210\u529f\u4e00\u534a\u5931\u8d25&#034; \u7684\u72b6\u6001\u6700\u96be\u67e5\u3002<\/li>\n<li>Iterator.remove() \u662f\u552f\u4e00\u5141\u8bb8\u7684 &#034;\u8fb9\u904d\u5386\u8fb9\u5220&#034; \u7684\u65b9\u5f0f&#xff0c;\u56e0\u4e3a\u5b83\u4f1a\u540c\u6b65\u8fed\u4ee3\u5668\u5185\u90e8\u7684\u8ba1\u6570\u3002removeIf \u66f4\u7701\u4e8b&#xff0c;\u5185\u90e8\u5c31\u662f\u6309\u8fd9\u4e2a\u601d\u8def\u505a\u7684\u3002<\/li>\n<p>\u673a\u5236\u4e0a&#xff0c;ArrayList \u5185\u90e8\u6709\u4e2a modCount&#xff0c;\u6bcf\u6b21\u7ed3\u6784\u6027\u4fee\u6539&#xff08;\u589e\u3001\u5220\u3001\u6e05\u7a7a&#xff09;\u5c31 &#043;1&#xff1b;\u8fed\u4ee3\u5668\u521b\u5efa\u65f6\u8bb0\u4e0b\u5f53\u524d\u503c&#xff0c;\u6bcf\u6b21 next() \u524d\u5bf9\u6bd4&#xff0c;\u4e0d\u4e00\u81f4\u5c31\u629b ConcurrentModificationException\u3002\u8fd9\u53eb fail-fast&#xff0c;\u662f &#034;\u5c3d\u529b\u800c\u4e3a&#034; \u7684\u68c0\u67e5&#xff0c;\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u4fdd\u8bc1\u3002<\/p>\n<h4>3.5 \u5e38\u7528\u65b9\u6cd5\u901f\u67e5<\/h4>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<p>\u65b9\u6cd5<\/p>\n<\/td>\n<td>\n<p>\u4f5c\u7528<\/p>\n<\/td>\n<td>\n<p>\u8fd4\u56de\u503c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>add(E e)<\/p>\n<\/td>\n<td>\n<p>\u5c3e\u63d2<\/p>\n<\/td>\n<td>\n<p>boolean&#xff08;\u53ef\u53d8 List \u6052 true&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>add(int index, E e)<\/p>\n<\/td>\n<td>\n<p>\u63d2\u5230\u6307\u5b9a\u4f4d\u7f6e<\/p>\n<\/td>\n<td>\n<p>void<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>addAll(Collection&lt;? extends E&gt; c)<\/p>\n<\/td>\n<td>\n<p>\u5c3e\u63d2\u4e00\u6279<\/p>\n<\/td>\n<td>\n<p>boolean<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>remove(int index)<\/p>\n<\/td>\n<td>\n<p>\u5220\u6307\u5b9a\u4e0b\u6807<\/p>\n<\/td>\n<td>\n<p>E&#xff08;\u88ab\u5220\u5143\u7d20&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>remove(Object o)<\/p>\n<\/td>\n<td>\n<p>\u5220\u7b2c\u4e00\u4e2a\u5339\u914d\u5bf9\u8c61<\/p>\n<\/td>\n<td>\n<p>boolean<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>get(int index)<\/p>\n<\/td>\n<td>\n<p>\u53d6\u6307\u5b9a\u4e0b\u6807<\/p>\n<\/td>\n<td>\n<p>E<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>set(int index, E e)<\/p>\n<\/td>\n<td>\n<p>\u8986\u76d6\u6307\u5b9a\u4e0b\u6807<\/p>\n<\/td>\n<td>\n<p>E&#xff08;\u65e7\u503c&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>clear()<\/p>\n<\/td>\n<td>\n<p>\u6e05\u7a7a<\/p>\n<\/td>\n<td>\n<p>void<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>contains(Object o)<\/p>\n<\/td>\n<td>\n<p>\u662f\u5426\u5305\u542b<\/p>\n<\/td>\n<td>\n<p>boolean<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>indexOf(Object o)<\/p>\n<\/td>\n<td>\n<p>\u7b2c\u4e00\u4e2a\u5339\u914d\u7684\u4e0b\u6807<\/p>\n<\/td>\n<td>\n<p>int&#xff08;\u65e0\u5219 -1&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>lastIndexOf(Object o)<\/p>\n<\/td>\n<td>\n<p>\u6700\u540e\u4e00\u4e2a\u5339\u914d\u7684\u4e0b\u6807<\/p>\n<\/td>\n<td>\n<p>int&#xff08;\u65e0\u5219 -1&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>subList(int from, int to)<\/p>\n<\/td>\n<td>\n<p>\u622a\u53d6\u5b50\u5217\u8868&#xff08;\u5de6\u95ed\u53f3\u5f00&#xff09;<\/p>\n<\/td>\n<td>\n<p>List&lt;E&gt;&#xff08;\u89c6\u56fe&#xff09;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u56db\u3001subList \u662f\u89c6\u56fe&#xff0c;\u4e0d\u662f\u62f7\u8d1d<\/h3>\n<h4>4.1 \u6539\u5b50\u5217\u8868\u4f1a\u56de\u5199\u539f\u5217\u8868<\/h4>\n<p>\/\/ \u6587\u4ef6&#xff1a;SubListDemo.java<br \/>\nimport java.util.ArrayList;<br \/>\nimport java.util.ConcurrentModificationException;<br \/>\nimport java.util.List;<\/p>\n<p>public class SubListDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        List&lt;String&gt; cart &#061; new ArrayList&lt;&gt;();<br \/>\n        cart.add(&#034;\u82f9\u679c&#034;);<br \/>\n        cart.add(&#034;\u9999\u8549&#034;);<br \/>\n        cart.add(&#034;\u6a59\u5b50&#034;);<br \/>\n        cart.add(&#034;\u897f\u74dc&#034;);<\/p>\n<p>        \/\/ subList \u8fd4\u56de\u7684\u662f&#034;\u89c6\u56fe&#034;&#xff0c;\u4e0d\u662f\u65b0\u5217\u8868<br \/>\n        List&lt;String&gt; firstTwo &#061; cart.subList(0, 2);<br \/>\n        System.out.println(&#034;\u89c6\u56fe\u5185\u5bb9&#xff1a;&#034; &#043; firstTwo);<\/p>\n<p>        firstTwo.set(0, &#034;\u8461\u8404&#034;); \/\/ \u6539\u89c6\u56fe<br \/>\n        System.out.println(&#034;\u6539\u89c6\u56fe\u540e&#xff0c;\u539f\u5217\u8868&#xff1a;&#034; &#043; cart);<\/p>\n<p>        firstTwo.clear(); \/\/ \u6e05\u7a7a\u89c6\u56fe<br \/>\n        System.out.println(&#034;\u6e05\u7a7a\u89c6\u56fe\u540e&#xff0c;\u539f\u5217\u8868&#xff1a;&#034; &#043; cart);<\/p>\n<p>        \/\/ \u539f\u5217\u8868\u7ed3\u6784\u4e00\u53d8&#xff0c;\u4e4b\u524d\u62ff\u5230\u7684\u89c6\u56fe\u5c31\u5931\u6548\u4e86<br \/>\n        List&lt;String&gt; view &#061; cart.subList(0, cart.size());<br \/>\n        cart.add(&#034;\u67e0\u6aac&#034;); \/\/ \u7ed3\u6784\u6027\u4fee\u6539<br \/>\n        try {<br \/>\n            System.out.println(view.get(0));<br \/>\n        } catch (ConcurrentModificationException ex) {<br \/>\n            System.out.println(&#034;\u65e7\u89c6\u56fe\u5931\u6548&#xff1a;&#034; &#043; ex.getClass().getSimpleName());<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>\u89c6\u56fe\u5185\u5bb9&#xff1a;[\u82f9\u679c, \u9999\u8549]<br \/>\n\u6539\u89c6\u56fe\u540e&#xff0c;\u539f\u5217\u8868&#xff1a;[\u8461\u8404, \u9999\u8549, \u6a59\u5b50, \u897f\u74dc]<br \/>\n\u6e05\u7a7a\u89c6\u56fe\u540e&#xff0c;\u539f\u5217\u8868&#xff1a;[\u6a59\u5b50, \u897f\u74dc]<br \/>\n\u65e7\u89c6\u56fe\u5931\u6548&#xff1a;ConcurrentModificationException<\/p>\n<p>subList \u8fd4\u56de\u7684\u5bf9\u8c61\u5185\u90e8\u8bb0\u7740 &#034;\u539f\u5217\u8868 &#043; \u504f\u79fb\u91cf &#043; \u957f\u5ea6&#034;&#xff0c;\u5b83\u7684 get\u3001set\u3001clear \u90fd\u662f\u5728\u539f\u5217\u8868\u4e0a\u64cd\u4f5c\u3002\u6240\u4ee5&#xff1a;<\/p>\n<ul>\n<li>set \u6539\u7684\u662f\u539f\u5217\u8868\u5bf9\u5e94\u4f4d\u7f6e&#xff1b;<\/li>\n<li>clear \u5220\u7684\u662f\u539f\u5217\u8868\u5bf9\u5e94\u90a3\u4e00\u6bb5&#xff1b;<\/li>\n<li>\u5b83\u4e0d\u5360\u989d\u5916\u5185\u5b58&#xff0c;\u4f46\u4e5f\u4e0d\u7ed9\u4f60\u6570\u636e\u9694\u79bb\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a\u8bbe\u8ba1\u6709\u5b83\u7684\u7528\u9014 \u2014\u2014list.subList(0, 5).clear() \u662f &#034;\u5220\u6389\u524d 5 \u4e2a&#034; \u7684\u6807\u51c6\u5199\u6cd5&#xff0c;\u6bd4\u5faa\u73af\u5220\u5feb\u5f97\u591a\u3002\u4f46\u8981\u5f53\u72ec\u7acb\u526f\u672c\u7528\u7684\u65f6\u5019&#xff0c;\u5fc5\u987b\u81ea\u5df1\u590d\u5236\u4e00\u4efd&#xff1a;<\/p>\n<p>List&lt;String&gt; copy &#061; new ArrayList&lt;&gt;(cart.subList(0, 2));<\/p>\n<h4>4.2 \u89c6\u56fe\u7684 &#034;\u6709\u6548\u671f&#034;<\/h4>\n<p>\u89c6\u56fe\u672c\u8eab\u4e0d\u68c0\u67e5\u539f\u5217\u8868\u6709\u6ca1\u6709\u53d8&#xff0c;\u76f4\u5230\u4f60\u8c03\u7528\u5b83\u7684\u65b9\u6cd5 \u2014\u2014 \u90a3\u65f6\u5b83\u4f1a\u5bf9\u6bd4 modCount&#xff0c;\u53d1\u73b0\u88ab\u6539\u8fc7\u5c31\u629b ConcurrentModificationException\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u89c6\u56fe\u7684\u5931\u6548\u662f\u5ef6\u8fdf\u53d1\u73b0\u7684&#xff0c;\u9519\u8bef\u4f1a\u51fa\u73b0\u5728\u79bb\u539f\u56e0\u5f88\u8fdc\u7684\u5730\u65b9\u3002<\/p>\n<p>\u5b9e\u9645\u5199\u4ee3\u7801\u65f6\u7684\u5904\u7406\u539f\u5219\u5f88\u7b80\u5355&#xff1a;<\/p>\n<ul>\n<li>\u53ea\u8bfb\u3001\u4e34\u65f6\u770b\u51e0\u773c&#xff0c;\u76f4\u63a5\u7528 subList&#xff1b;<\/li>\n<\/ul>\n<ul>\n<li>\u8981\u4f20\u51fa\u53bb\u3001\u8981\u5b58\u8d77\u6765\u3001\u8981\u88ab\u522b\u4eba\u6539&#xff0c;\u4e00\u5f8b new ArrayList&lt;&gt;(&#8230;) \u590d\u5236\u3002<\/li>\n<\/ul>\n<h3>\u4e94\u3001\u4e0d\u53ef\u53d8\u5217\u8868\u4e0e equals \u8bed\u4e49<\/h3>\n<h4 style=\"background-color:transparent\">5.1 \u4e09\u79cd &#034;\u770b\u8d77\u6765\u662f List&#xff0c;\u5176\u5b9e\u4e0d\u80fd\u968f\u4fbf\u6539&#034; \u7684\u4e1c\u897f<\/h4>\n<p>\/\/ \u6587\u4ef6&#xff1a;ImmutableListDemo.java<br \/>\nimport java.util.ArrayList;<br \/>\nimport java.util.Arrays;<br \/>\nimport java.util.List;<\/p>\n<p>public class ImmutableListDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/ Arrays.asList&#xff1a;\u56fa\u5b9a\u957f\u5ea6&#xff0c;\u80fd\u6539\u5143\u7d20&#xff0c;\u4e0d\u80fd\u589e\u5220<br \/>\n        List&lt;String&gt; fixed &#061; Arrays.asList(&#034;\u82f9\u679c&#034;, &#034;\u9999\u8549&#034;, &#034;\u6a59\u5b50&#034;);<br \/>\n        fixed.set(0, &#034;\u8461\u8404&#034;);<br \/>\n        System.out.println(&#034;\u6539\u5143\u7d20\u540e&#xff1a;&#034; &#043; fixed);<br \/>\n        try {<br \/>\n            fixed.add(&#034;\u897f\u74dc&#034;);<br \/>\n        } catch (UnsupportedOperationException ex) {<br \/>\n            System.out.println(&#034;asList \u52a0\u5143\u7d20&#xff1a;&#034; &#043; ex.getClass().getSimpleName());<br \/>\n        }<\/p>\n<p>        \/\/ \u5b83\u80cc\u540e\u662f\u539f\u6570\u7ec4&#xff0c;\u6539\u89c6\u56fe\u4f1a\u6539\u5230\u6570\u7ec4<br \/>\n        String[] arr &#061; {&#034;A&#034;, &#034;B&#034;};<br \/>\n        List&lt;String&gt; arrView &#061; Arrays.asList(arr);<br \/>\n        arrView.set(0, &#034;X&#034;);<br \/>\n        System.out.println(&#034;\u539f\u6570\u7ec4\u7b2c\u4e00\u4e2a\u5143\u7d20&#xff1a;&#034; &#043; arr[0]);<\/p>\n<p>        \/\/ List.of&#xff1a;\u5b8c\u5168\u4e0d\u53ef\u53d8&#xff0c;\u8fde set \u90fd\u4e0d\u884c<br \/>\n        List&lt;String&gt; immutable &#061; List.of(&#034;\u82f9\u679c&#034;, &#034;\u9999\u8549&#034;, &#034;\u6a59\u5b50&#034;);<br \/>\n        try {<br \/>\n            immutable.set(0, &#034;\u8461\u8404&#034;);<br \/>\n        } catch (UnsupportedOperationException ex) {<br \/>\n            System.out.println(&#034;List.of \u6539\u5143\u7d20&#xff1a;&#034; &#043; ex.getClass().getSimpleName());<br \/>\n        }<\/p>\n<p>        \/\/ \u8981\u53ef\u53d8&#xff0c;\u590d\u5236\u4e00\u4efd<br \/>\n        List&lt;String&gt; mutable &#061; new ArrayList&lt;&gt;(List.of(&#034;\u82f9\u679c&#034;, &#034;\u9999\u8549&#034;, &#034;\u6a59\u5b50&#034;));<br \/>\n        mutable.add(&#034;\u897f\u74dc&#034;);<br \/>\n        System.out.println(&#034;\u590d\u5236\u51fa\u6765\u53ef\u4ee5\u6539&#xff1a;&#034; &#043; mutable);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>\u6539\u5143\u7d20\u540e&#xff1a;[\u8461\u8404, \u9999\u8549, \u6a59\u5b50]<br \/>\n\u539f\u6570\u7ec4\u7b2c\u4e00\u4e2a\u5143\u7d20&#xff1a;X<br \/>\nasList \u52a0\u5143\u7d20&#xff1a;UnsupportedOperationException<br \/>\nList.of \u6539\u5143\u7d20&#xff1a;UnsupportedOperationException<br \/>\n\u590d\u5236\u51fa\u6765\u53ef\u4ee5\u6539&#xff1a;[\u82f9\u679c, \u9999\u8549, \u6a59\u5b50, \u897f\u74dc]<\/p>\n<p>\u4e09\u8005\u7684\u533a\u522b&#xff1a;<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<p>\u6765\u6e90<\/p>\n<\/td>\n<td>\n<p>\u80fd\u5426 set<\/p>\n<\/td>\n<td>\n<p>\u80fd\u5426 add \/ remove<\/p>\n<\/td>\n<td>\n<p>\u5907\u6ce8<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Arrays.asList(&#8230;)<\/p>\n<\/td>\n<td>\n<p>\u80fd<\/p>\n<\/td>\n<td>\n<p>\u4e0d\u80fd<\/p>\n<\/td>\n<td>\n<p>\u80cc\u540e\u662f\u539f\u6570\u7ec4&#xff0c;set \u4f1a\u56de\u5199\u6570\u7ec4<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>List.of(&#8230;)<\/p>\n<\/td>\n<td>\n<p>\u4e0d\u80fd<\/p>\n<\/td>\n<td>\n<p>\u4e0d\u80fd<\/p>\n<\/td>\n<td>\n<p>JDK 9 \u8d77&#xff0c;\u4e14\u4e0d\u63a5\u53d7 null<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>new ArrayList&lt;&gt;(&#8230;)<\/p>\n<\/td>\n<td>\n<p>\u80fd<\/p>\n<\/td>\n<td>\n<p>\u80fd<\/p>\n<\/td>\n<td>\n<p>\u771f\u6b63\u7684\u53ef\u53d8\u526f\u672c<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Arrays.asList \u90a3\u4e2a &#034;\u56fa\u5b9a\u957f\u5ea6&#034; \u4e0d\u662f bug&#xff0c;\u5b83\u8fd4\u56de\u7684\u662f\u6570\u7ec4\u7684\u5305\u88c5\u89c6\u56fe&#xff0c;\u957f\u5ea6\u7531\u6570\u7ec4\u51b3\u5b9a&#xff0c;\u6240\u4ee5\u4e0d\u80fd\u589e\u5220\u3002\u8fd9\u4e2a\u7c7b\u5728\u628a\u6570\u7ec4\u8f6c\u6210\u96c6\u5408\u4f20\u7ed9\u65b9\u6cd5\u65f6\u5f88\u5e38\u89c1&#xff0c;\u8e29\u5751\u7387\u4e5f\u9ad8\u3002<\/p>\n<h4 style=\"background-color:transparent\">5.2 indexOf \/ contains \/ remove(Object) \u5168\u9760 equals<\/h4>\n<p>\/\/ \u6587\u4ef6&#xff1a;EqualsTrapDemo.java<br \/>\nimport java.util.ArrayList;<br \/>\nimport java.util.List;<\/p>\n<p>class Item {<br \/>\n    String name;<\/p>\n<p>    Item(String name) {<br \/>\n        this.name &#061; name;<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public String toString() {<br \/>\n        return name;<br \/>\n    }<br \/>\n}<\/p>\n<p>class ItemWithEquals {<br \/>\n    String name;<\/p>\n<p>    ItemWithEquals(String name) {<br \/>\n        this.name &#061; name;<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public boolean equals(Object o) {<br \/>\n        if (this &#061;&#061; o) {<br \/>\n            return true;<br \/>\n        }<br \/>\n        if (!(o instanceof ItemWithEquals)) {<br \/>\n            return false;<br \/>\n        }<br \/>\n        return name.equals(((ItemWithEquals) o).name);<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public int hashCode() {<br \/>\n        return name.hashCode();<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public String toString() {<br \/>\n        return name;<br \/>\n    }<br \/>\n}<\/p>\n<p>public class EqualsTrapDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/ \u6ca1\u91cd\u5199 equals&#xff1a;\u4e24\u4e2a&#034;\u540c\u540d&#034;\u5bf9\u8c61\u88ab\u5f53\u6210\u4e0d\u540c\u5bf9\u8c61<br \/>\n        List&lt;Item&gt; a &#061; new ArrayList&lt;&gt;();<br \/>\n        a.add(new Item(&#034;\u82f9\u679c&#034;));<br \/>\n        System.out.println(&#034;\u672a\u91cd\u5199 equals contains&#xff1a;&#034; &#043; a.contains(new Item(&#034;\u82f9\u679c&#034;)));<br \/>\n        System.out.println(&#034;\u672a\u91cd\u5199 equals indexOf&#xff1a;&#034; &#043; a.indexOf(new Item(&#034;\u82f9\u679c&#034;)));<\/p>\n<p>        \/\/ \u91cd\u5199 equals \u4e4b\u540e<br \/>\n        List&lt;ItemWithEquals&gt; b &#061; new ArrayList&lt;&gt;();<br \/>\n        b.add(new ItemWithEquals(&#034;\u82f9\u679c&#034;));<br \/>\n        System.out.println(&#034;\u91cd\u5199\u540e contains&#xff1a;&#034; &#043; b.contains(new ItemWithEquals(&#034;\u82f9\u679c&#034;)));<br \/>\n        System.out.println(&#034;\u91cd\u5199\u540e indexOf&#xff1a;&#034; &#043; b.indexOf(new ItemWithEquals(&#034;\u82f9\u679c&#034;)));<br \/>\n        System.out.println(&#034;\u91cd\u5199\u540e remove&#xff1a;&#034; &#043; b.remove(new ItemWithEquals(&#034;\u82f9\u679c&#034;)) &#043; &#034;&#xff0c;\u5269\u4f59&#xff1a;&#034; &#043; b);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>\u672a\u91cd\u5199 equals contains&#xff1a;false<br \/>\n\u672a\u91cd\u5199 equals indexOf&#xff1a;-1<br \/>\n\u91cd\u5199\u540e contains&#xff1a;true<br \/>\n\u91cd\u5199\u540e indexOf&#xff1a;0<br \/>\n\u91cd\u5199\u540e remove&#xff1a;true&#xff0c;\u5269\u4f59&#xff1a;[]<\/p>\n<p>List \u91cc\u6240\u6709 &#034;\u6309\u5bf9\u8c61&#034; \u7684\u64cd\u4f5c \u2014\u2014contains\u3001indexOf\u3001lastIndexOf\u3001remove(Object)\u2014\u2014 \u5185\u90e8\u90fd\u662f\u9010\u4e2a\u8c03\u7528 equals \u6bd4\u8f83\u3002\u6ca1\u91cd\u5199 equals \u65f6&#xff0c;\u7528\u7684\u662f Object \u7684\u9ed8\u8ba4\u5b9e\u73b0&#xff0c;\u6bd4\u7684\u662f &#034;\u662f\u4e0d\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61&#034;&#xff0c;\u6240\u4ee5\u4e24\u4e2a\u5185\u5bb9\u76f8\u540c\u7684\u65b0\u5bf9\u8c61\u6c38\u8fdc\u4e0d\u76f8\u7b49\u3002<\/p>\n<p>\u8fd9\u4e5f\u89e3\u91ca\u4e86\u4e00\u4e2a\u5e38\u89c1\u56f0\u60d1&#xff1a;\u4ece\u6570\u636e\u5e93\u67e5\u51fa\u6765\u4e24\u6761\u5185\u5bb9\u4e00\u6837\u7684\u8bb0\u5f55&#xff0c;list.remove(\u53e6\u4e00\u6761) \u5220\u4e0d\u6389&#xff0c;\u56e0\u4e3a\u90a3\u662f\u4e24\u4e2a\u4e0d\u540c\u5bf9\u8c61\u3002<\/p>\n<p>\u91cd\u5199 equals \u65f6\u5fc5\u987b\u8fde\u5e26\u91cd\u5199 hashCode\u3002List \u53ea\u7528 equals&#xff0c;\u4f46\u540c\u4e00\u4e2a\u5bf9\u8c61\u653e\u8fdb HashSet \u6216\u5f53 HashMap \u7684 key \u65f6&#xff0c;hashCode \u4e0d\u5bf9\u4f1a\u5bfc\u81f4 &#034;\u660e\u660e\u76f8\u7b49\u5374\u627e\u4e0d\u5230&#034;\u3002\u8fd9\u662f\u53e6\u4e00\u4e2a\u5751&#xff0c;\u8fd9\u91cc\u5148\u8bb0\u4e00\u53e5\u3002<\/p>\n<h3 style=\"background-color:transparent\">\u516d\u3001ArrayList \u4e0e LinkedList \u600e\u4e48\u9009<\/h3>\n<p>\u4e24\u8005\u90fd\u5b9e\u73b0 List&#xff0c;\u63a5\u53e3\u884c\u4e3a\u4e00\u81f4&#xff0c;\u5dee\u522b\u5728\u5e95\u5c42&#xff1a;<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<p>\u64cd\u4f5c<\/p>\n<\/td>\n<td>\n<p>ArrayList<\/p>\n<\/td>\n<td>\n<p>LinkedList<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>get(i) \/ set(i, x)<\/p>\n<\/td>\n<td>\n<p>O (1)&#xff08;\u6570\u7ec4\u4e0b\u6807\u76f4\u63a5\u5b9a\u4f4d&#xff09;<\/p>\n<\/td>\n<td>\n<p>O (n)&#xff08;\u8981\u4ece\u5934 \/ \u5c3e\u8d70\u8fc7\u53bb&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u5c3e\u90e8 add<\/p>\n<\/td>\n<td>\n<p>\u5747\u644a O (1)&#xff0c;\u6269\u5bb9\u65f6\u8981\u6574\u4f53\u62f7\u8d1d<\/p>\n<\/td>\n<td>\n<p>O(1)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u5934\u90e8 add(0, x)<\/p>\n<\/td>\n<td>\n<p>O (n)&#xff0c;\u6240\u6709\u5143\u7d20\u540e\u79fb<\/p>\n<\/td>\n<td>\n<p>O(1)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>remove(0)<\/p>\n<\/td>\n<td>\n<p>O(n)<\/p>\n<\/td>\n<td>\n<p>O(1)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u989d\u5916\u5185\u5b58<\/p>\n<\/td>\n<td>\n<p>\u6570\u7ec4 &#043; \u9884\u7559\u5bb9\u91cf<\/p>\n<\/td>\n<td>\n<p>\u6bcf\u4e2a\u5143\u7d20\u4e00\u4e2a\u8282\u70b9\u5bf9\u8c61&#xff08;\u524d\u540e\u6307\u9488&#xff09;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9009\u6cd5\u5f88\u7b80\u5355&#xff1a;<\/p>\n<ul>\n<li>\u7edd\u5927\u591a\u6570\u573a\u666f\u7528 ArrayList\u3002\u771f\u5b9e\u4e1a\u52a1\u91cc &#034;\u6309\u4e0b\u6807\u53d6\u3001\u5c3e\u90e8\u8ffd\u52a0&#034; \u5360\u4e5d\u6210&#xff0c;ArrayList \u5728\u8fd9\u4e24\u4ef6\u4e8b\u4e0a\u90fd\u4e0d\u5dee&#xff1b;LinkedList \u7684 get(i) \u662f O (n)&#xff0c;\u4e00\u4e0d\u5c0f\u5fc3\u5728\u5faa\u73af\u91cc\u5199 get(i)&#xff0c;\u590d\u6742\u5ea6\u76f4\u63a5\u4ece O (n) \u53d8\u6210 O (n\u00b2)\u3002<\/li>\n<\/ul>\n<ul>\n<li>\u53ea\u6709\u9891\u7e41\u5728\u5934\u5c3e\u589e\u5220\u3001\u51e0\u4e4e\u4e0d\u6309\u4e0b\u6807\u8bbf\u95ee\u7684\u573a\u666f&#xff08;\u6bd4\u5982\u62ff\u5b83\u5f53\u961f\u5217\u7528&#xff09;&#xff0c;\u624d\u8f6e\u5230 LinkedList\u3002<\/li>\n<\/ul>\n<p>\u8bb0\u4f4f\u4e00\u53e5\u5c31\u591f&#xff1a;LinkedList \u5feb\u7684\u662f &#034;\u6539\u94fe\u8868\u7ed3\u6784&#034;&#xff0c;\u6162\u7684\u662f &#034;\u627e\u7b2c i \u4e2a&#034;\u3002<\/p>\n<h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<ul>\n<li>List \u6bd4 Collection \u591a\u7684\u5c31\u662f\u4e0b\u6807&#xff1a;\u6709\u5e8f\u3001\u53ef\u91cd\u590d\u3001\u80fd\u6309\u4f4d\u7f6e\u8bfb\u5199\u3002<\/li>\n<\/ul>\n<ul>\n<li>remove \u6709\u4e24\u4e2a\u91cd\u8f7d&#xff1a;remove(int) \u5220\u4e0b\u6807\u3001\u8fd4\u56de\u5143\u7d20&#xff1b;remove(Object) \u5220\u5bf9\u8c61\u3001\u8fd4\u56de\u5e03\u5c14\u3002List&lt;Integer&gt; \u6309\u503c\u5220\u8981\u5199 remove(Integer.valueOf(x))\u3002<\/li>\n<\/ul>\n<ul>\n<li>set \u8fd4\u56de\u65e7\u503c&#xff1b;indexOf \u4ece\u5de6\u627e\u3001lastIndexOf \u4ece\u53f3\u627e&#xff0c;\u627e\u4e0d\u5230\u8fd4\u56de -1&#xff1b;subList(from, to) \u5de6\u95ed\u53f3\u5f00\u3002<\/li>\n<\/ul>\n<ul>\n<li>\u904d\u5386\u4e2d\u5220\u9664\u5fc5\u987b\u7528 Iterator.remove() \u6216 removeIf&#xff0c;for-each \u76f4\u63a5\u5220\u4f1a\u629b ConcurrentModificationException&#xff0c;\u800c\u4e14\u5220\u9664\u5f80\u5f80\u5df2\u7ecf\u751f\u6548\u4e86\u4e00\u534a\u3002<\/li>\n<\/ul>\n<ul>\n<li>subList \u662f\u89c6\u56fe&#xff1a;\u6539\u5b83\u4f1a\u56de\u5199\u539f\u5217\u8868&#xff0c;\u539f\u5217\u8868\u7ed3\u6784\u4e00\u53d8\u5b83\u5c31\u5931\u6548\u3002\u8981\u72ec\u7acb\u526f\u672c\u5c31 new ArrayList&lt;&gt;(&#8230;)\u3002<\/li>\n<\/ul>\n<ul>\n<li>Arrays.asList \u56fa\u5b9a\u957f\u5ea6&#xff08;\u80fd set \u4e0d\u80fd\u589e\u5220&#xff09;\u3001List.of \u5b8c\u5168\u4e0d\u53ef\u53d8\u3001\u8981\u53ef\u53d8\u5c31\u590d\u5236\u4e00\u4efd\u3002<\/li>\n<\/ul>\n<ul>\n<li>contains \/ indexOf \/ remove(Object) \u5168\u9760 equals&#xff0c;\u81ea\u5b9a\u4e49\u7c7b\u4e0d\u91cd\u5199\u5c31\u627e\u4e0d\u5230\u3002<\/li>\n<\/ul>\n<h3>\u81ea\u6d4b\u9898<\/h3>\n<li>List&lt;Integer&gt; list &#061; new ArrayList&lt;&gt;(List.of(10, 20, 30)); \u6267\u884c list.remove(1) \u4e4b\u540e&#xff0c;list \u7684\u5185\u5bb9\u662f&#xff1a;<\/li>\n<p>A. [10, 20]<\/p>\n<p>B. [10, 30]<\/p>\n<p>C. [20, 30]<\/p>\n<p>D. \u629b\u5f02\u5e38<\/p>\n<li>list.subList(0, 2) \u8fd4\u56de\u7684\u662f\u4ec0\u4e48&#xff1f;\u5bf9\u5b83\u7684\u4fee\u6539\u4f1a\u5f71\u54cd\u539f\u5217\u8868\u5417&#xff1f;<\/li>\n<li>\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\u4e3a\u4ec0\u4e48\u4f1a\u629b\u5f02\u5e38&#xff1f;<\/li>\n<p>for (String s : list) {<\/p>\n<p>if (s.equals(&#034;x&#034;)) {<\/p>\n<p>list.remove(s);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<li>\u5224\u65ad\u5bf9\u9519&#xff1a;<\/li>\n<p>\u2460 List.of(&#034;a&#034;, &#034;b&#034;).add(&#034;c&#034;) \u4f1a\u629b UnsupportedOperationException<\/p>\n<p>\u2461 Arrays.asList(&#8230;) \u8fd4\u56de\u7684\u5217\u8868\u53ef\u4ee5 add \u5143\u7d20<\/p>\n<p>\u2462 \u81ea\u5b9a\u4e49\u7c7b\u6ca1\u91cd\u5199 equals \u65f6&#xff0c;list.contains(\u540c\u5185\u5bb9\u7684\u65b0\u5bf9\u8c61) \u8fd4\u56de false<\/p>\n<h3>\u7b54\u6848<\/h3>\n<li>B<\/li>\n<li>\u8fd4\u56de\u7684\u662f\u89c6\u56fe&#xff0c;\u4fee\u6539\u4f1a\u56de\u5199\u5230\u539f\u5217\u8868<\/li>\n<li>for-each \u7528\u7684\u662f\u8fed\u4ee3\u5668&#xff0c;\u904d\u5386\u4e2d\u4fee\u6539\u5217\u8868\u7ed3\u6784\u4f1a\u89e6\u53d1 fail-fast \u68c0\u67e5<\/li>\n<li>\u2460 true \u2461 false \u2462 true<\/li>\n<p>      <span id=\"quality-guide-article-end\" aria-hidden=\"true\" style=\"display:block;height:1px;margin-bottom:-1px\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[244,99,190,1813,305],"topic":[],"class_list":["post-124533","post","type-post","status-publish","format-standard","hentry","category-server","tag-244","tag-java","tag-190","tag-1813","tag-305"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7262\u5927\u5e26\u4f60\u5b66java\u6570\u636e\u7ed3\u6784-\u4e4blist - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/124533.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7262\u5927\u5e26\u4f60\u5b66java\u6570\u636e\u7ed3\u6784-\u4e4blist - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/124533.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-18T19:56:35+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/124533.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/124533.html\",\"name\":\"\u7262\u5927\u5e26\u4f60\u5b66java\u6570\u636e\u7ed3\u6784-\u4e4blist - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-11-18T19:56:35+00:00\",\"dateModified\":\"2026-11-18T19:56:35+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/124533.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/124533.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/124533.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7262\u5927\u5e26\u4f60\u5b66java\u6570\u636e\u7ed3\u6784--\u4e4blist\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7262\u5927\u5e26\u4f60\u5b66java\u6570\u636e\u7ed3\u6784-\u4e4blist - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/124533.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7262\u5927\u5e26\u4f60\u5b66java\u6570\u636e\u7ed3\u6784-\u4e4blist - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content","og_url":"https:\/\/www.wsisp.com\/helps\/124533.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-11-18T19:56:35+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/124533.html","url":"https:\/\/www.wsisp.com\/helps\/124533.html","name":"\u7262\u5927\u5e26\u4f60\u5b66java\u6570\u636e\u7ed3\u6784-\u4e4blist - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-11-18T19:56:35+00:00","dateModified":"2026-11-18T19:56:35+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/124533.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/124533.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/124533.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7262\u5927\u5e26\u4f60\u5b66java\u6570\u636e\u7ed3\u6784--\u4e4blist"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/124533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=124533"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/124533\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=124533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=124533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=124533"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=124533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}