打印集合中的自定义类时, 如何显示出自定义类成员变量的值?

集合中有自定义类, 打印集合的各个元素, 代码如下:

public class Te {
    public static void main(String[] args) {
        Collection c= new ArrayList();
        c.add(new Person1(23,1001));
        System.out.println(c);
    }
}

class Person1{
    int age;
    int id;

    public Person1(int age, int id) {
        super();
        this.age = age;
        this.id = id;
    }

}

我的运行结果是内存地址:
[sxt.zzy.Person1@15db9742]

如何使运行结果体现成员变量的值, 如
Person1 [age=23, id=1001]

自己去重写toString()方法就可以了

Iterator it = c.iterator();
while (it.hasNext()) {
Person1 p = (Person1) it.next();
System.out.println("Person1 [age= " + p.getAge()+",id="+p.getId()+"]");
}
确保Person1对象中有getter和setter