Dear all,
My friend send me typical java puzzle about java.util.ArrayList
which is getting messy. Please help me out. It's not a homework.
import java.util.*;
public class MyInt ______ ________ {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add(new MyInt(2));
list.add(new MyInt(1));
Collections.sort(list);
System.out.println(list);
}
private int i;
public MyInt(int i) { this.i = i; }
public String toString() { return Integer.toString(i); }
________ int ___________ {
MyInt i2 = (MyInt)o;
return ________;
}
}
Hints , fill the underlines with below :
implements
extends
Sortable
Object
Comparable
protected
public
i = i2.i
i
i2.i=i
compare(MyInt o, MyInt i2)
compare(Object o, Object i2)
sort(Object o) sort(MyInt o)
compareTo(MyInt o)
compareTo(Object o)
2006-08-27
21:39:40
·
2 answers
·
asked by
K Ban
2
in
Programming & Design