I created my own MyArrayList but it can not be sorted. A normal Arraylist can be sorted by Collections.sort but mine can not. Could some one tell me where is wrong?
import java.util.*;
public class TestMyArrayList
{
public static void main(String[] args){
String[] subjects = {"EIE320", "EIE558", "EIE375", "EIE424"};
Integer[] marks = {90,85,70,80};
MyArrayList<String> sList = new MyArrayList<String>(subjects);
Collections.sort(sList);
sList.print();
MyArrayList<Integer> mList = new MyArrayList<Integer>(marks);
Collections.sort(mList);
mList.print();
}
}
public class MyArrayList<E> extends ArrayList<E>
implements List<E>
{
private List<E> data;
public MyArrayList()
{
}
public MyArrayList(E[] inputdata){
super();
data = new ArrayList<E>();
for(E e:inputdata){
data.add(e);
}
}
public void print(){
for(Iterator iter = data.iterator();iter.hasNext();){
System.out.print(iter.next() + " ");
}
System.out.println(" ");
}
}