Java ArrayList 初始化
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());
}
}
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇: 爬虫的常见陷阱以及Java的爬虫思路
