我设置了这个 toString 方法
public String toString (){
String result;
result = "Ideal Family";
result += "\n"+person1.toString();
result += "\n"+person2.toString();
result += "\n"+person3.toString();
result += "\n"+person4.toString();
result += "\n"+pet1.toString();
result += "\n"+car1.toString();
result += "\n"+car2.toString();
result += "\n"+homeAddress.toString();
return result;
}
在其中我按照我希望输出它们的顺序列出对象。有没有办法根据对象中的值重新排序列表。特别是在 Person 类中,基于实例变量 int 对人员对象进行重新排序。
Person 类采用这些参数
public Person (String personName,String personGender,String personSS,int personAge){
name = personName;
ss = personSS;
age = personAge;
gender = personGender;
}