Reputation: 2497
I have a Arraylist: ArrayList<PlayerBean> playerlist = new ArrayList<PlayerBean>();
from an Object that includes a String and an double (Name and points).
public class PlayerBean{private String name;private double points;}
However for one of my Spinners I want to show only the name (String) in my Arraylist.
How do I manage to delete(remove) the double(points)?
I tried this without any success any ideas?
I am using the swinger for android. any idea?
ArrayList<PlayerBean> playerlist = new ArrayList<PlayerBean>();
List<String> namesOnly = filterNames(playerlist);
private List<String> filterNames(ArrayList<PlayerBean> playerlist12) {
List<String> names = new ArrayList<String>();
for(PlayerBean b : playerlist12)
{
names.add(b.getName());
}
return names;
}
Upvotes: 0
Views: 151
Reputation: 6197
Rather than removing them, why don't you make a new array List of String type, and assign all the names into this list. So you don't have any points.
Upvotes: 0
Reputation: 88707
Your list contains PlayerBean
objects and you can't temporarily delete member variables from objects. Thus you can't remove points
from the list.
You could either use a List<String>
instead or provide a spinner model that only displays the name. I assume you're using Swing, don't you?
Upvotes: 1