import java.util.*;
class A
{
private ArrayList <B> bList;
private Random generator = new Random();
A(List<B> initialList)
{
bList = new ArrayList<B> ();
int listSize = initialList.size();
bList.ensureCapacity(listSize);
for (B b : initialList)
{
int bIndex = generator.nextInt(listSize);
bList.add(bIndex , b);
}
}
}
class B
{
}
I ended up with a new error that is an out of range error when I insert blist.add(bIndex , b);
After Debugging it appears that ensureCapacity doesn't do its job.