java - How can you print multiple ArrayLists next to each other -


i have arraylist of object called process , each process has arraylist of integers allocation, max , need, each process has 3 arraylists it. trying make table looks this

              allocation       max           need  process 1    1 2 3 4          1 2 3 4     1 2 3 4   process 2    5 7 8 9          5 7 8 9     5 7 8 9   process 3    1 2 3 4          1 2 3 4     1 2 3 4   process 4    5 7 8 9          5 7 8 9     5 7 8 9  

etc each number it's own slot size of of arrays of 4. code trying

 public string tostring() {     string temp = "";     string tempallo = "";     string tempmax = "";     string tempneed = "";      (int j = 0; j < allocation.size(); j++) {         tempallo = allocation.get(j).tostring() + " ";         tempmax = max.get(j).tostring() + " ";         tempneed = need.get(j).tostring() + " ";     }      temp = id + "\t" + tempallo + "\t" + tempmax + "\t" + tempneed + "\n";      return temp; } 

but prints out

                   allocation       max           need      process 1        4             4              4       process 2        9             9              9       process 3        4             4              4      process 4        9             9              9  

so printing out last one. thank in advanced help

it should be: (note +=)

tempallo += allocation.get(j).tostring() + " "; tempmax += need.get(j).tostring() + " "; tempneed += allocation.get(j).tostring() + " "; 

i suggest use stringbuilder variables temp, tempallo,.. instead of string.

so do,

tempallo.append(allocation.get(j).tostring()).append(" "); 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -