I am using an ArrayList
within my code which gets populated by a EditText
field but I am wanting to limit the ArrayList
so it can only
You modify you setter method like this.
private static ArrayList playerList = new ArrayList();
public boolean addToPlayerList(String input) {
if (playerList.size() < 10) {
playerList.add(input);
return true;
} else {
return false;
}
}
Or
You can extend ArrayList
and create your own customized class.
public class MyArrayList extends ArrayList {
@Override
public boolean add(String input) {
if (this.size() < 10) {
return super.add(input);
} else {
return false;
}
}
}