mirror of
https://github.com/CyC2018/CS-Notes.git
synced 2025-07-04 23:58:38 +08:00
auto commit
This commit is contained in:
@ -63,8 +63,13 @@ boolean 只有两个值:true、false,可以使用 1 bit 来存储,但是
|
||||
基本类型都有对应的包装类型,基本类型与其对应的包装类型之间的赋值使用自动装箱与拆箱完成。
|
||||
|
||||
```java
|
||||
<<<<<<< HEAD
|
||||
Integer x = 2; // 装箱 调用了 Integer.valueOf(2)
|
||||
int y = x; // 拆箱 调用了 Integer.intValue(x)
|
||||
=======
|
||||
Integer x = 2; // 装箱 调用了 Integer.valueOf(2);
|
||||
int y = x; // 拆箱 调用了 Integer.intValue(x);
|
||||
>>>>>>> 7ae8fc396136c44742ab6d5e5a90a3a17fac5af7
|
||||
```
|
||||
|
||||
## 缓存池
|
||||
@ -78,6 +83,11 @@ new Integer(123) 与 Integer.valueOf(123) 的区别在于:
|
||||
Integer x = new Integer(123);
|
||||
Integer y = new Integer(123);
|
||||
System.out.println(x == y); // false
|
||||
|
||||
Integer x = 123; //调用了Integer.valueOf(123);
|
||||
Integer y = 123; //如果数值在[-128,127]之间,便返回指向缓冲池中已经存在的对象的引用;否则创建一个新的Integer对象。
|
||||
System.out.println(x==y); //true
|
||||
|
||||
Integer z = Integer.valueOf(123);
|
||||
Integer k = Integer.valueOf(123);
|
||||
System.out.println(z == k); // true
|
||||
@ -154,7 +164,11 @@ System.out.println(m == n); // true
|
||||
|
||||
## 概览
|
||||
|
||||
<<<<<<< HEAD
|
||||
String 被声明为 final,因此它不可被继承。(Integer 等包装类也不能被继承)
|
||||
=======
|
||||
String 被声明为 final,因此它不可被继承。(Integer等包装类也不能被继承)
|
||||
>>>>>>> 7ae8fc396136c44742ab6d5e5a90a3a17fac5af7
|
||||
|
||||
在 Java 8 中,String 内部使用 char 数组存储数据。
|
||||
|
||||
|
@ -650,7 +650,7 @@ static int indexFor(int h, int length) {
|
||||
| capacity | table 的容量大小,默认为 16。需要注意的是 capacity 必须保证为 2 的 n 次方。|
|
||||
| size | 键值对数量。 |
|
||||
| threshold | size 的临界值,当 size 大于等于 threshold 就必须进行扩容操作。 |
|
||||
| loadFactor | 装载因子,table 能够使用的比例,threshold = capacity * loadFactor。|
|
||||
| loadFactor | 装载因子,table 能够使用的比例,threshold = (int)(newCapacity * loadFactor)。|
|
||||
|
||||
```java
|
||||
static final int DEFAULT_INITIAL_CAPACITY = 16;
|
||||
@ -767,7 +767,12 @@ static final int tableSizeFor(int cap) {
|
||||
|
||||
### 8. 链表转红黑树
|
||||
|
||||
<<<<<<< HEAD
|
||||
从 JDK 1.8 开始,一个桶存储的链表长度大于等于 8 时会将链表转换为红黑树。
|
||||
=======
|
||||
从 JDK 1.8 开始,一个桶存储的链表长度大于 8 时会将链表转换为红黑树。
|
||||
应该是:从 JDK 1.8 开始, table的长度也就是HashMap的capacity(不是size)不能小于64而且在桶存储的链表长度为8时(准确的说是长度为7并且在继续塞第8个时),转换成红黑树,而不是超过8。
|
||||
>>>>>>> 7ae8fc396136c44742ab6d5e5a90a3a17fac5af7
|
||||
|
||||
### 9. 与 HashTable 的比较
|
||||
|
||||
|
Reference in New Issue
Block a user