请大家看看我做的对吗?
编程实现类MyList继承于ArrayList ,重写equal()方法,实现如下功能:
如果两个MyList的实例MY1,MY2不为空,并且其长度相同,而且对应元素也相等。则ML1.equal(ML2)=true 解:import java.util.*;
class MyList extends ArrayList { public boolean equal(MyList t1,MyList t2) { Iterator m1=t1.iterator(); Iterator m2=t2.iterator(); int n1=0; int n2=0; while(m1.hasNext()) { m1.next(); n1++; } while(m2.hasNext()) { m2.next(); n2++; } if(n1==n2) { return true; } else { return false; } } } public class Test1 {
public static void main(String[] args) { } }