![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java
Hank_dev
码农
展开
-
为什么HashMap、HashSet是线程不安全的(JDK 1.8)
1. HashMap<K, V>以put()方法为例,结合JDK源码分析/** * Constructs an empty <tt>HashMap</tt> with the default initial capacity * (16) and the default load factor (0.75). */public HashMap() {...原创 2020-04-13 14:39:41 · 947 阅读 · 0 评论 -
Fail-fast & Fail-safe
Fail-fast单线程操作iterator时(以ArrayList为例)List<Integer> integers = new ArrayList<>();integers.add(1);integers.add(2);integers.add(3);/** fail-fast in Iterator* Throw ConcurrentModificat...原创 2019-12-10 11:45:50 · 147 阅读 · 0 评论 -
String vs StringBuffer vs StringBuilder
可变性String 对象不可变。当给 String 引用赋予变化时,会创建新的 String 对象,原字符串对象失去引用。String 类中使用 final 关键字修饰字符数组来保存字符串,private final char value[]StringBuffer & StringBuilder 对象可变。它们均继承自 AbstractStringBuilder 类,在 Abst...原创 2019-11-30 17:21:42 · 189 阅读 · 0 评论