### Question:
Collection extends jsimple.lang.Iterable<E> { public Object[] toArray() { int collectionSize = size(), index = 0; Iterator<E> it = iterator(); Object[] array = new Object[collectionSize]; while (index < collectionSize) { array[index++] = it.next(); } return array; } protected  Collection(); boolean add(E object); boolean addAll(Collection<? extends E> collection); void clear(); boolean contains(E object); boolean containsAll(Collection<E> collection); boolean isEmpty(); @Override abstract Iterator<E> iterator(); boolean remove(E object); boolean removeAll(Collection<E> collection); boolean retainAll(Collection<E> collection); abstract int size(); Object[] toArray(); void toArray(E[] contents); @Override String toString();  }### Answer:
@Test public void testToArrayTypeless() { Collection<String> ac = new TestToArrayTypelessCollection(this); Object[] array = ac.toArray(); assertEquals(3, array.length); for (Object o : array) { if (!"0".equals(o) && !"1".equals(o) && !"2".equals(o)) { fail("an unexpected element was removed"); } } }
@Test public void testToArrayTyped() { Collection<String> ac = new TestToArrayTypedCollection(this); String[] csa = new String[3]; ac.toArray(csa); assertEquals(3, csa.length); assertEquals("0", csa[0]); assertEquals("1", csa[1]); assertEquals("2", csa[2]); }