Skip to content

Instantly share code, notes, and snippets.

@lichenbo
Created July 10, 2013 06:53
Show Gist options
  • Save lichenbo/5964001 to your computer and use it in GitHub Desktop.
Save lichenbo/5964001 to your computer and use it in GitHub Desktop.
public ArrayList(int initialCapacity) {
super();
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal Capacity: "+
initialCapacity);
this.elementData = new Object[initialCapacity];
}
public ArrayList() {
this(10);
}
public ArrayList(Collection<? extends E> c) {
elementData = c.toArray();
size = elementData.length;
// c.toArray might (incorrectly) not return Object[] (see 6260652)
if (elementData.getClass() != Object[].class)
elementData = Arrays.copyOf(elementData, size, Object[].class);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment