0

I am storing an ArrayList in Cloud Firestore where the index is the month and the value is a value! like so :

mList.add(0, 10);  //where 0 is January and 10 is its correspondent value  
mList.add(1, 144);
mList.add(2, 23);
//...
mList.add(11, 332);

I want to update let's say february, what I normally would do is:

mList.set(1, 100); 
//since the index starts at 0, 
//February would be at index 1 and the value gets changed from 144 to 100

This is my model class:

public class History {
    private ArrayList<Integer> valuesList = new ArrayList<>(12);

    public History() {}

    public History(ArrayList<Integer> valuesList) {
        this.valuesList = valuesList;
    }

    public ArrayList<Integer> getValuesList() {
        return valuesList;
    }

    public void setValuesList(ArrayList<Integer> valuesList) {
        this.valuesList = valuesList;
    }
}

I know that need to use .update(data) but I do not exactly how to update a specific value by the index, so the question is how to it ?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Thorvald
  • 3,424
  • 6
  • 40
  • 66

0 Answers0