a.add()应该写在一个方法内
public class Array {
ArrayList a = new ArrayList();
public Array() {
a.add(1);
a.add(2);
}
public String toString() {
StringBuilder str = new StringBuilder();
for (Object i : a) {
str.append(i + ",");
}
return str.substring(0, str.length() - 1);
}
} |