diff --git a/src/java/io/InputStream.java b/src/java/io/InputStream.java
index d6702c6..4a1f97a 100644
--- a/src/java/io/InputStream.java
+++ b/src/java/io/InputStream.java
@@ -162,7 +162,8 @@ public int read(byte b[]) throws IOException {
* b.length - off
* @see java.io.InputStream#read()
*
- * 将流中的数据读入,放在byte数组的地off位置的len位置
+ * 将流中的数据读入,放在byte数组的第off位置的len位置
+ * 该read(b, off, len)方法只是简单地反复调用方法read()
*/
public int read(byte b[], int off, int len) throws IOException {
if (b == null) {
@@ -170,6 +171,7 @@ public int read(byte b[], int off, int len) throws IOException {
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
+ // 如果len为零,则不会读取字节并返回0 ;
return 0;
}
diff --git a/src/java/util/ArrayList.java b/src/java/util/ArrayList.java
index 5616402..ca90806 100644
--- a/src/java/util/ArrayList.java
+++ b/src/java/util/ArrayList.java
@@ -25,10 +25,11 @@
package java.util;
+import sun.misc.SharedSecrets;
+
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
-import sun.misc.SharedSecrets;
/**
* Resizable-array implementation of the List interface. Implements
@@ -110,12 +111,13 @@ public class ArrayList extends AbstractList
private static final long serialVersionUID = 8683452581122892189L;
/**
- * Default initial capacity.
+ * Default initial capacity. 默认容量
*/
private static final int DEFAULT_CAPACITY = 10;
/**
* Shared empty array instance used for empty instances.
+ * size=0的空实例对象
*/
private static final Object[] EMPTY_ELEMENTDATA = {};
@@ -131,19 +133,20 @@ public class ArrayList extends AbstractList
* The capacity of the ArrayList is the length of this array buffer. Any
* empty ArrayList with elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA
* will be expanded to DEFAULT_CAPACITY when the first element is added.
+ * 保存ArrayList中数据的数组
*/
transient Object[] elementData; // non-private to simplify nested class access
/**
* The size of the ArrayList (the number of elements it contains).
- *
+ * ArrayList的实际数据的数量
* @serial
*/
private int size;
/**
* Constructs an empty list with the specified initial capacity.
- *
+ * 带容量参数的构造
* @param initialCapacity the initial capacity of the list
* @throws IllegalArgumentException if the specified initial capacity
* is negative
@@ -152,6 +155,7 @@ public ArrayList(int initialCapacity) {
if (initialCapacity > 0) {
this.elementData = new Object[initialCapacity];
} else if (initialCapacity == 0) {
+ // 1.6版本的是直接初始化一个容量为10的对象,现在是初始化为容量=0的对象
this.elementData = EMPTY_ELEMENTDATA;
} else {
throw new IllegalArgumentException("Illegal Capacity: "+
@@ -161,6 +165,7 @@ public ArrayList(int initialCapacity) {
/**
* Constructs an empty list with an initial capacity of ten.
+ * 空参构造,默认容量=0,1.6版本的默认容量为10
*/
public ArrayList() {
this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;
@@ -170,7 +175,7 @@ public ArrayList() {
* Constructs a list containing the elements of the specified
* collection, in the order they are returned by the collection's
* iterator.
- *
+ * 创建一个包含collection的ArrayList
* @param c the collection whose elements are to be placed into this list
* @throws NullPointerException if the specified collection is null
*/
@@ -181,7 +186,7 @@ public ArrayList(Collection extends E> c) {
if (elementData.getClass() != Object[].class)
elementData = Arrays.copyOf(elementData, size, Object[].class);
} else {
- // replace with empty array.
+ // replace with empty array. 依然将数据为0的情况独立出来,替换为容量=0的对象
this.elementData = EMPTY_ELEMENTDATA;
}
}
@@ -190,6 +195,7 @@ public ArrayList(Collection extends E> c) {
* Trims the capacity of this ArrayList instance to be the
* list's current size. An application can use this operation to minimize
* the storage of an ArrayList instance.
+ * 将当前容量值设为 =实际元素个数
*/
public void trimToSize() {
modCount++;
@@ -204,6 +210,7 @@ public void trimToSize() {
* Increases the capacity of this ArrayList instance, if
* necessary, to ensure that it can hold at least the number of elements
* specified by the minimum capacity argument.
+ * 确定ArrayList的容量
*
* @param minCapacity the desired minimum capacity
*/