[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"site-config":3,"primary-menu":6,"cat-java-collection":85,"catposts-java-collection":98,"post-detail-post-jc-iterator-fail-fast-6950a006":207},{"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":96,"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":37,"hideFromList":95,"preventParentPostCascadeQuery":95},"Java 集合面试题","","Java 集合框架面试题：HashMap、ConcurrentHashMap 等核心容器的结构与源码原理。",false,{"permalink":97,"postCount":73,"visiblePostCount":73},"\u002Fcategories\u002Fjava-collection",[99,123,144,165,186],{"metadata":100,"spec":103,"status":112,"categories":117},{"name":101,"creationTimestamp":102},"post-jc-iterator-fail-fast-6950a006","2026-09-13T10:00:55.410836Z",{"title":104,"slug":105,"cover":93,"excerpt":106,"publishTime":108,"categories":109,"tags":110,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},"什么是 fail-fast 机制？","jc-iterator-fail-fast",{"raw":93,"autoGenerate":107},true,"2026-09-13T10:00:55.460328Z",[87],[],"PUBLIC",{"permalink":113,"excerpt":114,"lastModifyTime":115,"phase":116},"\u002Farchives\u002Fjc-iterator-fail-fast","一、定义 在用迭代器遍历集合时，如果集合结构被修改（增\u002F删），迭代器会立即抛出 ConcurrentModificationException，这就是 fail-fast。 二、实现原理 集合内部维护 modCount 记录结构修改次数。迭代器创建时记录 expectedModCount = mod","2026-09-16T09:13:48.072882Z","PUBLISHED",[118],{"metadata":119,"spec":121,"status":122,"postCount":73},{"name":87,"creationTimestamp":88,"labels":120},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":37,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"metadata":124,"spec":127,"status":134,"categories":138},{"name":125,"creationTimestamp":126},"post-jc-set-impl-56908363","2026-09-13T10:00:55.238233Z",{"title":128,"slug":129,"cover":93,"excerpt":130,"publishTime":131,"categories":132,"tags":133,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},"HashSet 和 TreeSet 的区别？","jc-set-impl",{"raw":93,"autoGenerate":107},"2026-09-13T10:00:55.284648Z",[87],[],{"permalink":135,"excerpt":136,"lastModifyTime":137,"phase":116},"\u002Farchives\u002Fjc-set-impl","一、底层实现 HashSet：内部是 HashMap，元素作为 HashMap 的 key，value 是固定 Object。 TreeSet：内部是 TreeMap，基于红黑树。 二、对比 维度 HashSet TreeSet 有序性 无序 自然排序或定制排序 元素要求 重写 equals\u002Fhas","2026-09-16T09:13:47.112793Z",[139],{"metadata":140,"spec":142,"status":143,"postCount":73},{"name":87,"creationTimestamp":88,"labels":141},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":37,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"metadata":145,"spec":148,"status":155,"categories":159},{"name":146,"creationTimestamp":147},"post-jc-hashmap-concurrent-64bd43b8","2026-09-13T10:00:55.033490Z",{"title":149,"slug":150,"cover":93,"excerpt":151,"publishTime":152,"categories":153,"tags":154,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},"ConcurrentHashMap 如何保证线程安全？","jc-hashmap-concurrent",{"raw":93,"autoGenerate":107},"2026-09-13T10:00:55.084097Z",[87],[],{"permalink":156,"excerpt":157,"lastModifyTime":158,"phase":116},"\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",[160],{"metadata":161,"spec":163,"status":164,"postCount":73},{"name":87,"creationTimestamp":88,"labels":162},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":37,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"metadata":166,"spec":169,"status":176,"categories":180},{"name":167,"creationTimestamp":168},"post-jc-hashmap-principle-21acf5b7","2026-09-13T10:00:54.826428Z",{"title":170,"slug":171,"cover":93,"excerpt":172,"publishTime":173,"categories":174,"tags":175,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},"HashMap 的底层实现原理？","jc-hashmap-principle",{"raw":93,"autoGenerate":107},"2026-09-13T10:00:54.884321Z",[87],[],{"permalink":177,"excerpt":178,"lastModifyTime":179,"phase":116},"\u002Farchives\u002Fjc-hashmap-principle","一、数据结构 JDK 1.8 后 HashMap = 数组 + 链表 + 红黑树。 数组是主体，通过 (n-1) & hash 定位桶。 哈希冲突时，同桶元素挂成链表。 链表长度 ≥ 8 且数组长度 ≥ 64 时，链表转红黑树；节点数 ≤ 6 时转回链表。 二、put 流程 计算 key 的 has","2026-09-16T09:13:44.648455Z",[181],{"metadata":182,"spec":184,"status":185,"postCount":73},{"name":87,"creationTimestamp":88,"labels":183},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":37,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"metadata":187,"spec":190,"status":197,"categories":201},{"name":188,"creationTimestamp":189},"post-jc-arraylist-vs-linkedlist-064907ec","2026-09-13T10:00:54.635697Z",{"title":191,"slug":192,"cover":93,"excerpt":193,"publishTime":194,"categories":195,"tags":196,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},"ArrayList 和 LinkedList 的区别？","jc-arraylist-vs-linkedlist",{"raw":93,"autoGenerate":107},"2026-09-13T10:00:54.707259Z",[87],[],{"permalink":198,"excerpt":199,"lastModifyTime":200,"phase":116},"\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",[202],{"metadata":203,"spec":205,"status":206,"postCount":73},{"name":87,"creationTimestamp":88,"labels":204},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":37,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"metadata":208,"spec":209,"status":213,"categories":214,"content":220},{"name":101,"creationTimestamp":102},{"title":104,"slug":105,"cover":93,"excerpt":210,"publishTime":108,"categories":211,"tags":212,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},{"raw":93,"autoGenerate":107},[87],[],{"permalink":113,"excerpt":114,"lastModifyTime":115,"phase":116},[215],{"metadata":216,"spec":218,"status":219,"postCount":73},{"name":87,"creationTimestamp":88,"labels":217},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":37,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"content":221,"raw":221},"\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>"]