dimanche 22 février 2015

How can I add a string to an array?

I've been trying to figure out how add a string to an array. I have a class which represents a list and I want to add "cup" to the list by calling addTo. I've tried this, but it fills the entire array and then when the method is called again it overwrites the entire array:



public void addTo(java.lang.String item){
option = new String[20];//already declared
++position;
option[position] = item;
}


Why does it do this?


Aucun commentaire:

Enregistrer un commentaire