我在这里定义了一个自定义对象:
public class ContactObject {
public String contactName;
public String contactNo;
public String image;
public boolean selected;
public String getName() {
return contactName;
}
public void setName(String contactName) {
this.contactName = contactName;
}
public String getNumber() {
return contactNo;
}
public void setNumber(String contactNo) {
this.contactNo = contactNo;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}
我已经填充了这个自定义对象(binderContacts)的ArrayList,但是现在我想将它转换为普通的ArrayList,其中包含我的数组列表中所有contactNo的列表。有人可以在这帮忙吗?
public class ContactsListClass {
public static final ArrayList<ContactObject> phoneList = new ArrayList<ContactObject>();
public static final ArrayList<ContactObject> binderContacts = new ArrayList<ContactObject>();
}
答案 0 :(得分:0)
假设您使用的是Java 8:
ArrayList<String> contactNos = binderContacts.stream().map(contact -> contact.getNumber()).collect(Collectors.toList());
答案 1 :(得分:0)
List<String> contactNos = new ArrayList<String>();
for (ContactObject o : phoneList) {
contactNos.add(o.getNumber());
}