[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"site-config":3,"primary-menu":6,"cat-java-collection":85,"catposts-java-collection":99,"post-detail-post-jc-iterator-fail-fast-6950a006":208},{"config":4,"socialLinks":5},null,[],{"metadata":7,"spec":10,"menuItems":20},{"name":8,"creationTimestamp":9},"primary","2026-09-12T06:13:55.024154Z",{"displayName":11,"menuItems":12},"主菜单",[13,14,15,16,17,18,19],"88c3f10b-321c-4092-86a8-70db00251b74","menu-item-izrtmxer","c4c814d1-0c2c-456b-8c96-4864965fee94","menu-item-column","menu-item-tools","menu-item-zsxq","menu-item-ocrxlczu",[21,30,40,49,58,67,76],{"displayName":22,"metadata":23,"spec":25,"status":28,"children":29},"首页",{"name":13,"creationTimestamp":24},"2026-09-12T06:13:54.422830Z",{"displayName":22,"href":26,"priority":27,"menuName":8},"\u002F",0,{"displayName":22,"href":26},[],{"displayName":31,"metadata":32,"spec":34,"status":38,"children":39},"Java面试八股",{"name":14,"creationTimestamp":33},"2026-09-13T09:42:02.854891Z",{"displayName":31,"href":35,"target":36,"priority":37,"menuName":8},"\u002Fjava-interview","_self",1,{"displayName":31,"href":35},[],{"displayName":41,"metadata":42,"spec":44,"status":47,"children":48},"文章",{"name":15,"creationTimestamp":43},"2026-09-12T06:13:54.457307Z",{"displayName":41,"href":45,"priority":46,"menuName":8},"\u002Farchives",2,{"displayName":41,"href":45},[],{"displayName":50,"metadata":51,"spec":53,"status":56,"children":57},"项目实战",{"name":16,"creationTimestamp":52},"2026-09-14T00:35:08.138170Z",{"displayName":50,"href":54,"target":36,"priority":55,"menuName":8},"\u002Fcolumn",3,{"displayName":50,"href":54},[],{"displayName":59,"metadata":60,"spec":62,"status":65,"children":66},"在线工具",{"name":17,"creationTimestamp":61},"2026-09-14T00:35:08.171474Z",{"displayName":59,"href":63,"target":36,"priority":64,"menuName":8},"\u002Ftools",4,{"displayName":59,"href":63},[],{"displayName":68,"metadata":69,"spec":71,"status":74,"children":75},"知识星球",{"name":18,"creationTimestamp":70},"2026-09-14T00:35:08.199145Z",{"displayName":68,"href":72,"target":36,"priority":73,"menuName":8},"\u002Fzsxq",5,{"displayName":68,"href":72},[],{"displayName":77,"metadata":78,"spec":80,"status":83,"children":84},"特价云服务器",{"name":19,"creationTimestamp":79},"2026-09-25T15:30:59.201614Z",{"displayName":77,"href":81,"target":36,"priority":82,"menuName":8},"\u002Fserver",6,{"displayName":77,"href":81},[],{"metadata":86,"spec":91,"status":97,"postCount":73},{"name":87,"creationTimestamp":88,"labels":89},"java-collection","2026-09-13T09:13:25.521651Z",{"haloweb.section":90},"interview",{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},"Java 集合面试题","","Java 集合框架面试题：HashMap、ConcurrentHashMap 等核心容器的结构与源码原理。",10,false,{"permalink":98,"postCount":73,"visiblePostCount":73},"\u002Fcategories\u002Fjava-collection",[100,124,145,166,187],{"metadata":101,"spec":104,"status":113,"categories":118},{"name":102,"creationTimestamp":103},"post-jc-iterator-fail-fast-6950a006","2026-09-13T10:00:55.410836Z",{"title":105,"slug":106,"cover":93,"excerpt":107,"publishTime":109,"categories":110,"tags":111,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},"什么是 fail-fast 机制？","jc-iterator-fail-fast",{"raw":93,"autoGenerate":108},true,"2026-09-13T10:00:55.460328Z",[87],[],"PUBLIC",{"permalink":114,"excerpt":115,"lastModifyTime":116,"phase":117},"\u002Farchives\u002Fjc-iterator-fail-fast","一、定义 在用迭代器遍历集合时，如果集合结构被修改（增\u002F删），迭代器会立即抛出 ConcurrentModificationException，这就是 fail-fast。 二、实现原理 集合内部维护 modCount 记录结构修改次数。迭代器创建时记录 expectedModCount = mod","2026-09-16T09:13:48.072882Z","PUBLISHED",[119],{"metadata":120,"spec":122,"status":123,"postCount":73},{"name":87,"creationTimestamp":88,"labels":121},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"metadata":125,"spec":128,"status":135,"categories":139},{"name":126,"creationTimestamp":127},"post-jc-set-impl-56908363","2026-09-13T10:00:55.238233Z",{"title":129,"slug":130,"cover":93,"excerpt":131,"publishTime":132,"categories":133,"tags":134,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},"HashSet 和 TreeSet 的区别？","jc-set-impl",{"raw":93,"autoGenerate":108},"2026-09-13T10:00:55.284648Z",[87],[],{"permalink":136,"excerpt":137,"lastModifyTime":138,"phase":117},"\u002Farchives\u002Fjc-set-impl","一、底层实现 HashSet：内部是 HashMap，元素作为 HashMap 的 key，value 是固定 Object。 TreeSet：内部是 TreeMap，基于红黑树。 二、对比 维度 HashSet TreeSet 有序性 无序 自然排序或定制排序 元素要求 重写 equals\u002Fhas","2026-09-16T09:13:47.112793Z",[140],{"metadata":141,"spec":143,"status":144,"postCount":73},{"name":87,"creationTimestamp":88,"labels":142},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"metadata":146,"spec":149,"status":156,"categories":160},{"name":147,"creationTimestamp":148},"post-jc-hashmap-concurrent-64bd43b8","2026-09-13T10:00:55.033490Z",{"title":150,"slug":151,"cover":93,"excerpt":152,"publishTime":153,"categories":154,"tags":155,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},"ConcurrentHashMap 如何保证线程安全？","jc-hashmap-concurrent",{"raw":93,"autoGenerate":108},"2026-09-13T10:00:55.084097Z",[87],[],{"permalink":157,"excerpt":158,"lastModifyTime":159,"phase":117},"\u002Farchives\u002Fjc-hashmap-concurrent","一、JDK 1.7：分段锁 内部是 Segment 数组，每个 Segment 是一个小 HashMap，put 时只锁当前 Segment，并发度 = Segment 数（默认 16）。 二、JDK 1.8：CAS + synchronized 数组节点为空时，用 CAS 插入，无锁。 节点不为空","2026-09-16T09:13:46.058129Z",[161],{"metadata":162,"spec":164,"status":165,"postCount":73},{"name":87,"creationTimestamp":88,"labels":163},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"metadata":167,"spec":170,"status":177,"categories":181},{"name":168,"creationTimestamp":169},"post-jc-hashmap-principle-21acf5b7","2026-09-13T10:00:54.826428Z",{"title":171,"slug":172,"cover":93,"excerpt":173,"publishTime":174,"categories":175,"tags":176,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},"HashMap 的底层实现原理？","jc-hashmap-principle",{"raw":93,"autoGenerate":108},"2026-09-13T10:00:54.884321Z",[87],[],{"permalink":178,"excerpt":179,"lastModifyTime":180,"phase":117},"\u002Farchives\u002Fjc-hashmap-principle","一、数据结构 JDK 1.8 后 HashMap = 数组 + 链表 + 红黑树。 数组是主体，通过 (n-1) & hash 定位桶。 哈希冲突时，同桶元素挂成链表。 链表长度 ≥ 8 且数组长度 ≥ 64 时，链表转红黑树；节点数 ≤ 6 时转回链表。 二、put 流程 计算 key 的 has","2026-09-16T09:13:44.648455Z",[182],{"metadata":183,"spec":185,"status":186,"postCount":73},{"name":87,"creationTimestamp":88,"labels":184},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"metadata":188,"spec":191,"status":198,"categories":202},{"name":189,"creationTimestamp":190},"post-jc-arraylist-vs-linkedlist-064907ec","2026-09-13T10:00:54.635697Z",{"title":192,"slug":193,"cover":93,"excerpt":194,"publishTime":195,"categories":196,"tags":197,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},"ArrayList 和 LinkedList 的区别？","jc-arraylist-vs-linkedlist",{"raw":93,"autoGenerate":108},"2026-09-13T10:00:54.707259Z",[87],[],{"permalink":199,"excerpt":200,"lastModifyTime":201,"phase":117},"\u002Farchives\u002Fjc-arraylist-vs-linkedlist","一、底层结构 ArrayList：基于动态数组，连续内存存储。 LinkedList：基于双向链表，节点分散存储。 二、性能对比 操作 ArrayList LinkedList 随机访问 O(1) O(n) 尾部追加 O(1)（均摊） O(1) 中间插入\u002F删除 O(n)（需移动元素） O(1)（定位","2026-09-16T09:13:43.711113Z",[203],{"metadata":204,"spec":206,"status":207,"postCount":73},{"name":87,"creationTimestamp":88,"labels":205},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"metadata":209,"spec":210,"status":214,"categories":215,"content":221},{"name":102,"creationTimestamp":103},{"title":105,"slug":106,"cover":93,"excerpt":211,"publishTime":109,"categories":212,"tags":213,"priority":27,"pinned":96,"deleted":96,"visible":112,"allowComment":108},{"raw":93,"autoGenerate":108},[87],[],{"permalink":114,"excerpt":115,"lastModifyTime":116,"phase":117},[216],{"metadata":217,"spec":219,"status":220,"postCount":73},{"name":87,"creationTimestamp":88,"labels":218},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":95,"hideFromList":96,"preventParentPostCascadeQuery":96},{"permalink":98,"postCount":73,"visiblePostCount":73},{"content":222,"raw":222},"\u003Ch2>一、定义\u003C\u002Fh2>\n\u003Cp>在用迭代器遍历集合时，如果集合结构被修改（增\u002F删），迭代器会立即抛出 \u003Ccode>ConcurrentModificationException\u003C\u002Fcode>，这就是 fail-fast。\u003C\u002Fp>\n\u003Ch2>二、实现原理\u003C\u002Fh2>\n\u003Cp>集合内部维护 \u003Ccode>modCount\u003C\u002Fcode> 记录结构修改次数。迭代器创建时记录 \u003Ccode>expectedModCount = modCount\u003C\u002Fcode>，每次 \u003Ccode>next()\u003C\u002Fcode> 检查两者是否相等，不等则抛异常。\u003C\u002Fp>\n\u003Ch2>三、触发场景\u003C\u002Fh2>\n\u003Cpre>\u003Ccode class=\"language-java\">List&lt;String&gt; list = new ArrayList&lt;&gt;(Arrays.asList(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;));\nfor (String s : list) {\n    list.remove(s);   \u002F\u002F 抛 ConcurrentModificationException\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>四、解决方案\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>用 \u003Ccode>Iterator.remove()\u003C\u002Fcode> 删除。\u003C\u002Fli>\n\u003Cli>JUC 的 CopyOnWriteArrayList 是 fail-safe，遍历时修改不抛异常（读的是快照）。\u003C\u002Fli>\n\u003C\u002Ful>"]