Question: I'm trying to create a 2d ArrayList(can't use Arrays). It will be an Arraylist of Arraylist ArrayList correlationMatrix = new ArrayList (); ArrayList newcorrelationMatrix =

I'm trying to create a 2d ArrayList(can't use Arrays). It will be an Arraylist of Arraylist

ArrayList> correlationMatrix = new ArrayList>(); ArrayList> newcorrelationMatrix = new ArrayList>(); ArrayList lastCorrelationMatrix = new ArrayList(); for (int i=0;i

correlationMatrix is filled with 5 ArrayList and the findCorrelation method takes 2 ArrayList as arguments. I'm trying to fill newcorrelationMatrix in a way that each row is each iteration of lastCorrelationMatrix. My thought process was that for example for i=0 fill lastCorrelationMatrix, and add that Arraylist to newcorrelationMatrix and then clear the content of lastCorrelationMatrix and go to i=1 and add the new lastCorrelationMatrix to newcorrelationMatrix, and so on. But for some reason is just printinig the i=4 value repeated 5 times. The method findCorrelation works, the purpose of me creating newcorrelationMatrix is that lastCorrelationMatrix after the method call fills it 20 elements and I need them to be output in a 5x4 matrix format. What am I doing wrong in this code, thanks.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!