Getting IndexOutOfBoundsException


#1

even though I am limiting my loop to the size of the array.
" for (int i=0; i < B.size() -1; i++){"


#2

if B.size()==0, then the index will be out of bounds.