ArrayList的Java帮助ArrayList不唯一

ArrayList的Java帮助ArrayList不唯一,java,arraylist,Java,Arraylist,我有一小部分代码只是半功能的。有人能解释一下为什么我的ArrayList>ALL_像素在每个位置都保持相同的值吗 //为什么这不能使每行的所有像素都是唯一的 for (int i = 0; i < FRAME_HEIGHT; i++) { HashMap<String, Double> t = boundsHistory.get(zoomNum); PI task = new PI(i, t); //this is th

我有一小部分代码只是半功能的。有人能解释一下为什么我的ArrayList>ALL_像素在每个位置都保持相同的值吗

//为什么这不能使每行的所有像素都是唯一的

    for (int i = 0; i < FRAME_HEIGHT; i++) {

        HashMap<String, Double> t = boundsHistory.get(zoomNum);
        PI task = new PI(i, t);
        //this is the problem. some where 
        ArrayList<Integer> temp = new ArrayList<Integer>();
        temp = task.execute();
        //System.out.println(temp);
        ALL_PIXELS.add(temp);
        //System.out.println(ALL_PIXELS.get(i));     //still unique here....WHYYYYYYY
        //System.out.println(temp);     //this shows that temp is a unique array each row

    }// end for loop    



    //why is all pixels seting the same vales to all of its sub arrays
    //System.out.println(ALL_PIXELS.get(3));
    //System.out.println(ALL_PIXELS.get(300));
for(int i=0;i

如果我在for循环后打印所有像素数组列表时,有什么建议可以确保它保持唯一。

task.execute()
返回什么,以及“每个位置的值相同”是什么意思?顺便说一句,您还可以编写
所有像素.add(task.execute())
,因为
temp
只保存
task.execute()
的返回值。这一行
ArrayList temp=new ArrayList()
是无用的,因为您在下一行
temp=task.execute()
上覆盖了
temp
。您没有提供足够的代码来回答问题。
PI.execute()
的实现似乎是最重要的缺失部分。在每次循环迭代中都检索
boundsHistory.get(zoomNum)
,但没有证据表明结果会随着迭代而变化,这有点奇怪。这并不是天生的错误(特别是如果结果可以改变),但是如果你可以依靠结果不改变,那么最好把它从循环中提出来。这是我的问题的一个更好的表示,代码非常适合这里