Java ArrayList 初始化,javaarraylist
分享于 点击 560 次 点评:137
Java ArrayList 初始化,javaarraylist
List thisRow = new ArrayList(10);
java.util.ArrayList.ArrayList(int initialCapacity)
ArrayList
public ArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity.
Parameters:
initialCapacity - the initial capacity of the list
Throws:
IllegalArgumentException - if the specified initial capacity is negative
这个构造方法是建立了初始容量为initialCapacity的List, 但它此时为空, size()是0.
import java.util.ArrayList;
import java.util.List;
public class ValidAnagram {
public static void main(String[] args) {
List<Integer> thisRow = new ArrayList<Integer>(10);
System.out.println(thisRow.size());
thisRow.add(1);
System.out.println(thisRow.size());
}
}
相关文章
- 暂无相关文章
用户点评