MCPcopy Create free account
hub / github.com/davidgiven/luje / ArrayList

Class ArrayList

lib/java/util/ArrayList.java:31–708  ·  view source on GitHub ↗

ArrayList is an implementation of List, backed by an array. All optional operations adding, removing, and replacing are supported. The elements can be any objects. @since 1.2

Source from the content-addressed store, hash-verified

29 * @since 1.2
30 */
31public class ArrayList<E> extends AbstractList<E> implements List<E>,
32 Cloneable, Serializable, RandomAccess {
33
34 private static final long serialVersionUID = 8683452581122892189L;
35
36 private transient int firstIndex;
37
38 private transient int size;
39
40 private transient E[] array;
41
42 /**
43 * Constructs a new instance of {@code ArrayList} with ten capacity.
44 */
45 public ArrayList() {
46 this(10);
47 }
48
49 /**
50 * Constructs a new instance of {@code ArrayList} with the specified
51 * capacity.
52 *
53 * @param capacity
54 * the initial capacity of this {@code ArrayList}.
55 */
56 public ArrayList(int capacity) {
57 if (capacity < 0) {
58 throw new IllegalArgumentException();
59 }
60 firstIndex = size = 0;
61 array = newElementArray(capacity);
62 }
63
64 /**
65 * Constructs a new instance of {@code ArrayList} containing the elements of
66 * the specified collection. The initial size of the {@code ArrayList} will
67 * be 10% larger than the size of the specified collection.
68 *
69 * @param collection
70 * the collection of elements to add.
71 */
72 public ArrayList(Collection<? extends E> collection) {
73 firstIndex = 0;
74 Object[] objects = collection.toArray();
75 size = objects.length;
76
77 // REVIEW: Created 2 array copies of the original collection here
78 // Could be better to use the collection iterator and
79 // copy once?
80 array = newElementArray(size + (size / 10));
81 System.arraycopy(objects, 0, array, 0, size);
82 modCount = 1;
83 }
84
85 @SuppressWarnings("unchecked")
86 private E[] newElementArray(int size) {
87 return (E[]) new Object[size];
88 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected