Have you tried the ‘Bag’ collection?
It might be exactly what you need.
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
public class Bag<E>
{
private final E[] array;
private int count;
public Bag(E e, int capacity)
{
this.array = (E[]) Array.newInstance(e.getClass(), capacity);
}
public final int count()
{
return count;
}
public final void put(E e)
{
// no checks... don't grow, just deal with the current capacity
array[count++] = e;
}
public final E swap(int index, E e)
{
E org = array[index];
array[index] = e;
return org;
}
public final E grab(int index)
{
return array[index];
}
public final int search(E e)
{
for (int i = 0; i < count; i++)
if (array[i] == e)
return i;
return -1;
}
public final void dispose(int index)
{
array[index] = array[--count];
array[count + 1] = null;
}
public final void sort(Comparator<E> c)
{
Arrays.sort(array, 0, count, c);
}
}