Java 对象列表到字符串列表
正在尝试将具有移动号码的对象列表转换为字符串列表Java 对象列表到字符串列表,java,android,Java,Android,正在尝试将具有移动号码的对象列表转换为字符串列表 contactsList1=response.body(); //this is an object list contactList1[Contacts] contactsList2=new ArrayList<String>(contactsList.size()); // this is the new list String for (Contacts contacts:contactsList){ contact
contactsList1=response.body(); //this is an object list contactList1[Contacts]
contactsList2=new ArrayList<String>(contactsList.size()); // this is the new list String
for (Contacts contacts:contactsList){
contactsList2.add(contacts!=null ? contacts.toString():null);
}
问题在于:
contacts.toString()
您需要重写toString方法:
@Override
public String toString() {
return phone;
}
post contact model Structure在
Contacts
类中显示您的toString
的定义。请注意,如果您不重写toString
,您将调用对象
toString。我编辑了我的问题并添加了它。您可以立即检查它Call contacts.getPhone()将其添加到您的contactList2中
@Override
public String toString() {
return phone;
}