code: public void set(int i, double y, double weight) {
          if (i < 0) {
              throw new IllegalArgumentException("Invalid index: i = " + i);
          }
  
          int nrows = size();
          if (i >= nrows) {
              for (int k = nrows; k <= i; k++) {
                  data.add(new Datum<>(new SparseArray()));
              }
          }
  
          Datum<SparseArray> datum = get(i);
          datum.y = y;
          datum.weight = weight;
      }
docs: Set the class label of real-valued response of a datum. If the index
  exceeds the current matrix size, the matrix will resize itself.
  @param i the row index of entry.
  @param y the class label or real-valued response of the datum.
  @param weight the optional weight of the datum.