Type-specific growable array collection classes. The classes in this
package are basically equivalent to type-specific versions of the
standard java.util.Vector
or newer
java.util.ArrayList
class. They support a few added
methods (including direct conversion to a typed array with
toArray()
) and some minor interface differences. The standard
public access methods in these classes are as follows:
Method Signature | From |
int add(type) | implementation class |
void add(int, type) | implementation class |
void clear() | {@link com.sosnoski.util.array.ArrayBase} |
Object clone() | implementation class |
void ensureCapacity(int) | {@link com.sosnoski.util.GrowableBase} |
type get(int) | implementation class |
void remove(int) | {@link com.sosnoski.util.array.ArrayBase} |
void remove(int, int) | {@link com.sosnoski.util.array.ArrayBase} |
void set(int, type) | implementation class |
void setSize(int) | {@link com.sosnoski.util.array.ArrayBase} |
int size() | {@link com.sosnoski.util.array.ArrayBase} |
type[] toArray() | implementation class |
type[] toArray(int, int) | implementation class |
The {@link com.sosnoski.util.array.ObjectArray} class also provides a pair of toArray
methods which allow the base element type of the array to be specified as
something other than Object
.
As with ArrayList
, the access methods are
unsynchronized for best performance. The user program must implement
appropriate locking if multiple threads need to access an
instance of these classes while that instance may be modified.
Collections of a primitive type and of a specific object type
are both supported. All variations derive directly from the
ArrayBase
base class. To define a growable array of a
new type, generally you can use one of the existing classes as a base
and do a text substitution of the type names.
For instance, to define a growable array of instances of
Thread
just copy StringArray.java
to a new file named ThreadArray.java
, then do a global
text substitution of "Thread" for "String" in the new file.
Primitive types are only slightly more complicated. byte
and
char
versions are included, and short
can be done
using one of these as a base and just substituting the type name. The other primitive
types, which are not promoted to int
in
expressions, can use the implementation for double
as a base.