我创建了自己的MyArrayList,但无法对其进行排序.一个普通的Arraylist可以分类,Collections.sort但我的不能.有人可以告诉我哪里错了吗?
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() + " "); …Run Code Online (Sandbox Code Playgroud)