JDK7 和JDK8的ArrayList的区别对比
发布时间:2023-01-11 03:54:27 212
相关标签:
示例
public class ArrayListTest { public static void main(String[] args) { ArrayList<Object> jdk = new ArrayList<>(); jdk.add(123); } }
初始化操作 ①调用无参构造器 jdk7从无参调用有参构造器,并初始化为10:/** * Constructs an empty list with an initial capacity of ten. */ public ArrayList() { this(10); } /** * 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 */ public ArrayList(int initialCapacity) { super(); if (initialCapacity < 0) throw new IllegalArgumentException("Illegal Capacity: "+ initialCapacity); this.elementData = new Object[initialCapacity]; }
文章来源: https://blog.51cto.com/learningfish/5996699
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报