public class DynamicIntArray
{
private static final int CAPACITY_INCREMENT = 10;
private static final int INITIAL_CAPACITY = 10;
private final int capacityIncrement;
public int length = 0;
public int[] array;
public DynamicIntArray(int initialCapacity, int capacityIncrement)
{
this.capacityIncrement = capacityIncrement;
this.array = new int[initialCapacity];
}
public DynamicIntArray()
{
this(CAPACITY_INCREMENT, INITIAL_CAPACITY);
}
public int append(int i)
{
final int offset = length;
if (offset == array.length)
{
int[] old = array;
array = new int[offset + capacityIncrement];
System.arraycopy(old, 0, array, 0, offset);
}
array[length++] = i;
return offset;
}
public void removeElementAt(int offset)
{
if (offset >= length)
{
throw new ArrayIndexOutOfBoundsException("offset too big");
}
if (offset < length)
{
System.arraycopy(array, offset+1, array, offset, length-offset-1);
length--;
}
}
}
Er hat keine setAt()-Methode, aber ich bin sicher, Sie verstehen die Idee.