### Question:
ArrayList extends List<E> { public void trimToSize() { E[] newArray = newElementArray(itemCount); SystemUtils.arraycopy(array, firstIndex, newArray, 0, itemCount); array = newArray; firstIndex = 0; modCount = 0; } ArrayList();  ArrayList(int capacity);  ArrayList(Collection<E> collection);  ArrayList(E... args); @Override void add(int location, E object); @Override boolean add(E object); @Override boolean addAll(int location, Collection<? extends E> collection); @Override boolean addAll(Collection<? extends E> collection); @Override void clear(); @Override boolean contains(E object); void ensureCapacity(int minimumCapacity); @Override E get(int location); @Override int indexOf(E object); @Override boolean isEmpty(); @Override int lastIndexOf(E object); @Override Iterator<E> iterator(); @Override E remove(int location); @Override boolean remove(E object); @Override E set(int location, E object); @Override int size(); @Override Object[] toArray(); @Override void toArray(E[] contents); void sortInPlace(Comparator<E> comparator); void trimToSize();  }### Answer:
@Test public void testTrimToSize() { for (int i = 99; i > 24; i--) { alist.remove(i); } ((ArrayList<Object>) alist).trimToSize(); assertEquals("Returned incorrect size after trim", 25, alist.size()); for (int i = 0; i < alist.size(); i++) { assertTrue("Trimmed list contained incorrect elements", alist.get(i) == objArray[i]); } ArrayList<String> v = new ArrayList<String>(); v.add("a"); ArrayList<String> al = new ArrayList<String>(v); Iterator<String> it = al.iterator(); al.trimToSize(); try { it.next(); fail("should throw a ConcurrentModificationException"); } catch (ProgrammerError ioobe) { } }