Prompts-MCP 686 skills · ai / design / design-pattern / framework / fundamentals / habit / lang / tech-selection /mcp/sse
lang lang/java/collections/index.md medium

lang-java-collections-index

Java 集合四件事 — 容器选型 / Stream 用法 / 不可变集合 / 并发集合。Use when 选 List、Set、Map 实现 / 写 Stream 链 / 暴露只读集合 / 在多线程下共享集合时。

子项索引

子项 一句话
collection-choice skill List/Set/Map 实现选型 — ArrayList vs LinkedList、HashMap/TreeMap/LinkedHashMap、HashSet/TreeSet,及初始容量预估
stream-api skill Stream 正确用法 — collect/map/filter 主线、peek 不做副作用、parallelStream 慎用、toMap 处理重复 key
immutable-collections skill 暴露只读集合 — List.of/Map.of、Collections.unmodifiableList、防御性拷贝,以及 Arrays.asList 的固定长度坑
concurrent-collections skill 并发集合选型 — ConcurrentHashMap vs synchronizedMap、CopyOnWriteArrayList 适用场景,禁并发下用普通 HashMap

Collections · 子项索引

集合拆成四个独立决策点,按你正在做的事下钻:

你在做什么 进哪个
决定该用 ArrayList/LinkedList、HashMap/TreeMap、HashSet/TreeSet 哪个实现,怎么预估初始容量 collection-choice
写 Stream 链(map/filter/collect),纠结 peek、并行流、toMap 重复 key 怎么办 stream-api
要返回 / 暴露一个不让外部改的集合,或防御外部传入的集合 immutable-collections
集合要在多个线程间共享读写 concurrent-collections