I have a class where I am creating different "Processes", an attribute of this class is an linked list of Integers. I have created different class objects and to make it easy to loop through all of the process objects I have created, I am storing these objects in an arraylist in my main class - i understand how to individually access each linked list. What I am doing now is looping through my arraylist to access each objects linked list and adding these numbers into a queue called processQueue in my main class. so currently I have something like
ArrayList<MyClassName> processObjects = new ArrayList<MyClassName>();
for(int i = 0; i < processObjects.size(); i++){
for(int j = 0; j < processObjects.get(i).getQueue().size(); j++){
processQueue.add(processObjects.get(i).getQueue().get(j));
}
}
(this would be process object 1 linked list) = {2,1,5,4} (this would be process object 2 linked list) = {3,2,6,1}
so in the case that these two linkedlists are proviced, I would want processQueue to look like {2,3,1,2,5,6,4,1} - but instead right now im returning {2,1,5,4,3,2,6,1}
Any help for me understanding conceptually how to accomplish my goal of adding to the queue by column would be much appriciated!
Initially, I tried to do this the way i would with a 2D array like this for example
int[][] bruh = new int[3][3];
Test test = new Test();
int i = 0;
for(int row = 0; row < bruh.length;row++){
for(int col = 0; col < bruh.length; col++){
bruh[col][row] = i;
test.bruh.add(i);
}
i++;
}
But because i will not know the size of the linkedLists, this approach causes size errors