Java 如何相邻打印多个ArrayList

Java 如何相邻打印多个ArrayList,java,arraylist,Java,Arraylist,我有一个我称之为进程的对象的arraylist,每个进程都有一个用于分配、max和need的整数arraylist,因此每个进程基本上有3个arraylist。我想做一张像这样的桌子 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 Pro

我有一个我称之为进程的对象的arraylist,每个进程都有一个用于分配、max和need的整数arraylist,因此每个进程基本上有3个arraylist。我想做一张像这样的桌子

              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 
等 每个数字都是它自己的插槽,因此的所有数组的大小都是4。这是我正在尝试的代码

 public String toString() {
    String temp = "";
    String tempAllo = "";
    String tempMax = "";
    String tempNeed = "";

    for (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;
}
所以它只是打印出最后一个。感谢您在advanced中提供的帮助

它应该是:(注意
+=

我建议您使用
StringBuilder
作为变量
temp
tempAllo
,。。而不是
字符串

这样你就可以

tempAllo.append(allocation.get(j).toString()).append(" ");
尝试:

for(int j=0;j
tempAllo += allocation.get(j).toString() + " ";
tempMax += need.get(j).toString() + " ";
tempNeed += allocation.get(j).toString() + " ";
tempAllo.append(allocation.get(j).toString()).append(" ");
for (int j = 0; j < allocation.size(); j++) {
    tempAllo = tempAllo.concat(allocation.get(j).toString() + " ");
    tempMax = tempMax.concat(need.get(j).toString() + " ");
    tempNeed = tempNeed.concat(allocation.get(j).toString() + " ");
}