I'm looking for a method to overwrite/ replace a value in an arraylist, the arraylist itself is a value in a hashmap.
Here is a bit of the code that was provided for us.
public Equations(Double[][] matrix) {
// save input matrix into M -- it represents the equations
M = new HashMap<Integer,ArrayList<Double>>();
for (int i=0;i<matrix.length;i++) { // step through rows of matrix
ArrayList<Double> L = new ArrayList<Double>(Arrays.asList(matrix[i]));
M.put(i,L);
}
}
// handy method to return a specific coefficient in row/column
public Double Element(int row, int column) {
return M.get(row).get(column);
}
We are using Hashmaps to perform Gaussian Elimination. I have my Gaussian Elimination code prepared to find that row's factor, apply it to the first column's value in that row, and subtract that value from the value in the row before it. The resulting number is what I need to pass into the hashmap and arraylist to replace the value that was just factored and subtracted.
Is there a way for me to replace this number by number? Or do I need to construct a brand new arraylist, and replace the old arraylist using M.put(key, arraylist)?