Merge Sort

Im doing the Merge Sort:

class MergeSortextends Sorter_BK{

public MergeSort(ArrayList<Comparable> list){

super(list);

}

publicvoid sort(){

if (archive.size() <= 1)return;

ArrayList<Comparable> first =new ArrayList<Comparable>();

first.add(archive.size() / 2);

ArrayList<Comparable> second =new ArrayList<Comparable>();

second.add(archive.size() - first.size());

System.arraycopy(archive, 0, first, 0, first.size());

System.arraycopy(archive, first.size(), second, 0, second.size());

Sorting firstSorter =new Sorting(first);

Sorting secondSorter =new Sorting(second);

firstSorter.mergeSort();

secondSorter.mergeSort();

merge(first, second);

}

privatevoid merge(ArrayList<Comparable> first, ArrayList<Comparable> second){

int iFirst = 0;

int iSecond = 0;

int j = 0;

while (iFirst < first.size() && iSecond < second.size()){

if ((first.get(iFirst).compareTo(second.get(iSecond))) < 0){

archive.set(j, first.get(iFirst));

iFirst++;

}

else{

archive.set(j, second.get(iSecond));

iSecond++;

}

System.out.println(toString());

j++;

}

System.arraycopy(first, iFirst, archive, j, first.size() - iFirst);

System.arraycopy(second, iSecond, archive, j, second.size() - iSecond);

}

}

when i call the sort method i get this runtime error using an ArrayList

Exception in thread "main" java.lang.ArrayStoreException

at java.lang.System.arraycopy(Native Method)

at MergeSort.sort(Sorter_BK.java:125)

at Sorter_BK.main(Sorter_BK.java:54)

[2795 byte] By [darksssa] at [2007-11-27 1:55:56]
# 1
http://forum.java.sun.com/thread.jspa?threadID=5163763&tstart=0Duplicate post. No answers here as buttface got a response in his/her other thread.
floundera at 2007-7-12 1:29:39 > top of Java-index,Java Essentials,New To Java...