Skip to content

Commit 069ab10

Browse files
committed
auto commit
1 parent 532a5d8 commit 069ab10

File tree

6 files changed

+97
-30
lines changed

6 files changed

+97
-30
lines changed

docs/notes/Java 基础.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ boolean 只有两个值:true、false,可以使用 1 bit 来存储,但是
6464

6565
```java
6666
Integer x = 2; // 装箱 调用了 Integer.valueOf(2)
67-
int y = x; // 拆箱 调用了 Integer.intValue(x)
67+
int y = x; // 拆箱 调用了 X.intValue()
6868
```
6969

70+
- [Autoboxing and Unboxing](https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html)
71+
7072
## 缓存池
7173

7274
new Integer(123) 与 Integer.valueOf(123) 的区别在于:

docs/notes/Java 容器.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,53 @@ public synchronized E get(int index) {
299299
}
300300
```
301301

302-
### 2. 与 ArrayList 的比较
302+
### 2. 扩容
303+
304+
Vector 的构造函数可以传入 capacityIncrement 参数,它的作用是在扩容时使容量 capacity 增长 capacityIncrement。如果这个参数的值小于等于 0,扩容时每次都令 capacity 为原来的两倍。
305+
306+
```java
307+
public Vector(int initialCapacity, int capacityIncrement) {
308+
super();
309+
if (initialCapacity < 0)
310+
throw new IllegalArgumentException("Illegal Capacity: "+
311+
initialCapacity);
312+
this.elementData = new Object[initialCapacity];
313+
this.capacityIncrement = capacityIncrement;
314+
}
315+
```
316+
317+
```java
318+
private void grow(int minCapacity) {
319+
// overflow-conscious code
320+
int oldCapacity = elementData.length;
321+
int newCapacity = oldCapacity + ((capacityIncrement > 0) ?
322+
capacityIncrement : oldCapacity);
323+
if (newCapacity - minCapacity < 0)
324+
newCapacity = minCapacity;
325+
if (newCapacity - MAX_ARRAY_SIZE > 0)
326+
newCapacity = hugeCapacity(minCapacity);
327+
elementData = Arrays.copyOf(elementData, newCapacity);
328+
}
329+
```
330+
331+
调用没有 capacityIncrement 的构造函数时,capacityIncrement 值被设置为 0,也就是说默认情况下 Vector 每次扩容时容量都会翻倍。
332+
333+
```java
334+
public Vector(int initialCapacity) {
335+
this(initialCapacity, 0);
336+
}
337+
338+
public Vector() {
339+
this(10);
340+
}
341+
```
342+
343+
### 3. 与 ArrayList 的比较
303344

304345
- Vector 是同步的,因此开销就比 ArrayList 要大,访问速度更慢。最好使用 ArrayList 而不是 Vector,因为同步操作完全可以由程序员自己来控制;
305-
- Vector 每次扩容请求其大小的 2 倍空间,而 ArrayList 是 1.5 倍。
346+
- Vector 每次扩容请求其大小的 2 倍(也可以通过构造函数设置增长的容量),而 ArrayList 是 1.5 倍。
306347

307-
### 3. 替代方案
348+
### 4. 替代方案
308349

309350
可以使用 `Collections.synchronizedList();` 得到一个线程安全的 ArrayList。
310351

@@ -650,7 +691,7 @@ static int indexFor(int h, int length) {
650691
| capacity | table 的容量大小,默认为 16。需要注意的是 capacity 必须保证为 2 的 n 次方。|
651692
| size | 键值对数量。 |
652693
| threshold | size 的临界值,当 size 大于等于 threshold 就必须进行扩容操作。 |
653-
| loadFactor | 装载因子,table 能够使用的比例,threshold = capacity * loadFactor。|
694+
| loadFactor | 装载因子,table 能够使用的比例,threshold = (int)(newCapacity * loadFactor)|
654695

655696
```java
656697
static final int DEFAULT_INITIAL_CAPACITY = 16;

docs/notes/MySQL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ do {
242242
- 查询本身效率也可能会有所提升。例如下面的例子中,使用 IN() 代替连接查询,可以让 MySQL 按照 ID 顺序进行查询,这可能比随机的连接要更高效。
243243

244244
```sql
245-
SELECT * FROM tab
245+
SELECT * FROM tag
246246
JOIN tag_post ON tag_post.tag_id=tag.id
247247
JOIN post ON tag_post.post_id=post.id
248248
WHERE tag.tag='mysql';

notes/Java 基础.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,12 @@ boolean 只有两个值:true、false,可以使用 1 bit 来存储,但是
6363
基本类型都有对应的包装类型,基本类型与其对应的包装类型之间的赋值使用自动装箱与拆箱完成。
6464

6565
```java
66-
<<<<<<< HEAD
6766
Integer x = 2; // 装箱 调用了 Integer.valueOf(2)
68-
int y = x; // 拆箱 调用了 Integer.intValue(x)
69-
=======
70-
Integer x = 2; // 装箱 调用了 Integer.valueOf(2);
71-
int y = x; // 拆箱 调用了 Integer.intValue(x);
72-
>>>>>>> 7ae8fc396136c44742ab6d5e5a90a3a17fac5af7
67+
int y = x; // 拆箱 调用了 X.intValue()
7368
```
7469

70+
- [Autoboxing and Unboxing](https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html)
71+
7572
## 缓存池
7673

7774
new Integer(123) 与 Integer.valueOf(123) 的区别在于:
@@ -83,11 +80,6 @@ new Integer(123) 与 Integer.valueOf(123) 的区别在于:
8380
Integer x = new Integer(123);
8481
Integer y = new Integer(123);
8582
System.out.println(x == y); // false
86-
87-
Integer x = 123; //调用了Integer.valueOf(123);
88-
Integer y = 123; //如果数值在[-128,127]之间,便返回指向缓冲池中已经存在的对象的引用;否则创建一个新的Integer对象。
89-
System.out.println(x==y); //true
90-
9183
Integer z = Integer.valueOf(123);
9284
Integer k = Integer.valueOf(123);
9385
System.out.println(z == k); // true
@@ -164,11 +156,7 @@ System.out.println(m == n); // true
164156

165157
## 概览
166158

167-
<<<<<<< HEAD
168159
String 被声明为 final,因此它不可被继承。(Integer 等包装类也不能被继承)
169-
=======
170-
String 被声明为 final,因此它不可被继承。(Integer等包装类也不能被继承)
171-
>>>>>>> 7ae8fc396136c44742ab6d5e5a90a3a17fac5af7
172160

173161
在 Java 8 中,String 内部使用 char 数组存储数据。
174162

notes/Java 容器.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,53 @@ public synchronized E get(int index) {
299299
}
300300
```
301301

302-
### 2. 与 ArrayList 的比较
302+
### 2. 扩容
303+
304+
Vector 的构造函数可以传入 capacityIncrement 参数,它的作用是在扩容时使容量 capacity 增长 capacityIncrement。如果这个参数的值小于等于 0,扩容时每次都令 capacity 为原来的两倍。
305+
306+
```java
307+
public Vector(int initialCapacity, int capacityIncrement) {
308+
super();
309+
if (initialCapacity < 0)
310+
throw new IllegalArgumentException("Illegal Capacity: "+
311+
initialCapacity);
312+
this.elementData = new Object[initialCapacity];
313+
this.capacityIncrement = capacityIncrement;
314+
}
315+
```
316+
317+
```java
318+
private void grow(int minCapacity) {
319+
// overflow-conscious code
320+
int oldCapacity = elementData.length;
321+
int newCapacity = oldCapacity + ((capacityIncrement > 0) ?
322+
capacityIncrement : oldCapacity);
323+
if (newCapacity - minCapacity < 0)
324+
newCapacity = minCapacity;
325+
if (newCapacity - MAX_ARRAY_SIZE > 0)
326+
newCapacity = hugeCapacity(minCapacity);
327+
elementData = Arrays.copyOf(elementData, newCapacity);
328+
}
329+
```
330+
331+
调用没有 capacityIncrement 的构造函数时,capacityIncrement 值被设置为 0,也就是说默认情况下 Vector 每次扩容时容量都会翻倍。
332+
333+
```java
334+
public Vector(int initialCapacity) {
335+
this(initialCapacity, 0);
336+
}
337+
338+
public Vector() {
339+
this(10);
340+
}
341+
```
342+
343+
### 3. 与 ArrayList 的比较
303344

304345
- Vector 是同步的,因此开销就比 ArrayList 要大,访问速度更慢。最好使用 ArrayList 而不是 Vector,因为同步操作完全可以由程序员自己来控制;
305-
- Vector 每次扩容请求其大小的 2 倍空间,而 ArrayList 是 1.5 倍。
346+
- Vector 每次扩容请求其大小的 2 倍(也可以通过构造函数设置增长的容量),而 ArrayList 是 1.5 倍。
306347

307-
### 3. 替代方案
348+
### 4. 替代方案
308349

309350
可以使用 `Collections.synchronizedList();` 得到一个线程安全的 ArrayList。
310351

@@ -767,12 +808,7 @@ static final int tableSizeFor(int cap) {
767808

768809
### 8. 链表转红黑树
769810

770-
<<<<<<< HEAD
771811
从 JDK 1.8 开始,一个桶存储的链表长度大于等于 8 时会将链表转换为红黑树。
772-
=======
773-
从 JDK 1.8 开始,一个桶存储的链表长度大于 8 时会将链表转换为红黑树。
774-
应该是:从 JDK 1.8 开始, table的长度也就是HashMap的capacity(不是size)不能小于64而且在桶存储的链表长度为8时(准确的说是长度为7并且在继续塞第8个时),转换成红黑树,而不是超过8。
775-
>>>>>>> 7ae8fc396136c44742ab6d5e5a90a3a17fac5af7
776812

777813
### 9. 与 HashTable 的比较
778814

notes/MySQL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ do {
242242
- 查询本身效率也可能会有所提升。例如下面的例子中,使用 IN() 代替连接查询,可以让 MySQL 按照 ID 顺序进行查询,这可能比随机的连接要更高效。
243243

244244
```sql
245-
SELECT * FROM tab
245+
SELECT * FROM tag
246246
JOIN tag_post ON tag_post.tag_id=tag.id
247247
JOIN post ON tag_post.post_id=post.id
248248
WHERE tag.tag='mysql';

0 commit comments

Comments
 (0)