Java容器深入浅出之List、ListIterator和ArrayList
List是Collection接口的子接口,表示的是一种有序的、可重复元素的集合。 List接口的主要实现类ArrayList和Vector,底层都是维护了一套动态的,可扩展长度的Object[]数组,通过initialCapacity参数来动态地调整长度。因此,相比较父接口Collection所提供的公共增删改方法,List接口及实现类也定义了通过索引来增删查改元素,或者基于元素查找索引的方法。更一般地,ArrayList中的元素可以为null。 List及List新增的ListIterator接口 List接口的定义方法如下 1 public class TestList { 2 3 @SuppressWarnings("unlikely-arg-type") 4 public static void main(String[] args) { 5 6 List<String> books = new ArrayList<>(); 7 //List集合添加元素的顺序是有序的 8 books.add(new String("资本论")); 9 books.ad...