code: public RowMajorMatrixIterator rowMajorIterator() {
          return new RowMajorMatrixIterator(rows, columns) {
              private long limit = (long) rows * columns;
              private int i = - 1;
  
              @Override
              public int rowIndex() {
                  return i / columns;
              }
  
              @Override
              public int columnIndex() {
                  return i - rowIndex() * columns;
              }
  
              @Override
              public double get() {
                  return Matrix.this.get(rowIndex(), columnIndex());
              }
  
              @Override
              public void set(double value) {
                  Matrix.this.set(rowIndex(), columnIndex(), value);
              }
  
              @Override
              public boolean hasNext() {
                  return i + 1 < limit;
              }
  
              @Override
              public Double next() {
                  if(!hasNext()) {
                      throw new NoSuchElementException();
                  }
  
                  i++;
                  return get();
              }
          };
      }
docs: Returns a row-major matrix iterator.
  
  @return a row-major matrix iterator.