i get this error when i try to bubble sort my array list of objects by a string variable in the object:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at iContainer.sort(iContainer.java:90)
at main.main(main.java:9)
This is my sort:
public void sort()
{
for (int i=0; i<a.size(); i++)
{
for (int j=0; j<a.size(); j++)
{
if ((a.get(j).type).compareTo(a.get(j+1).type) > 0)
{
instrument tmp = a.get(j);
a.remove(j);
a.add(j,a.get(j+1));
a.add(j+1,tmp);
}
}
}
}