I am making a java application that balances chemical equations. I loop through each term and create two arraylists. In one arraylist, I have the set of all of the elements. For example (in the first term) if the equation is C6H12O6+O2=CO2+H2O, the arraylist will have {C, H, O}. In another, I have the corresponding numbers, so it will contain {6,12,6}. I need to combine all of these to form a matrix (3 by 4), which would be:
(0,0) = 6 (1,0) = 12 (2,0) = 6 (0,1) = 0 (1,1) = 0 (2,1) = 2 (0,2) = 1 (1,2) = 0 (2,2) = 2 (0,3) = 0 (1,3) = 2 (2,3) = 1
The matrix above is designed so that row 0 is C, row 1 is H, and row 2 is O. The columns are the terms (0, 1, 2, and 3)
Any suggestions for converting the arraylists into a matrix?