【发布时间】:2011-10-22 12:07:10
【问题描述】:
当我询问它是否包含指定的坐标时,我有一个 int 数组的 ArrayList 返回 false。它确实包含我请求的坐标,因此它应该返回 TRUE。
这是我的代码。
//debug code
for (int i = 0; i < Locations.size(); i++)
{
int[] TestLoc = Locations.get(i);
System.out.print(TestLoc[0] + " " + TestLoc[1] + " " + TestLoc[2] + " == " + Location[0] + " " + Location[1] + " " + Location[2] + "? - ");
if (Location == TestLoc)
{
System.out.println("TRUE");
}
else
{
System.out.println("FALSE");
}
}
//real code
if (Locations.contains(Location))
{
Locations.remove(Location);
}
else
{
System.out.println("FAIL");
}
并输出,当列表包含4个坐标时,请求坐标57、64、105。
56 64 105 == 57 64 105? - 错误
56 64 106 == 57 64 105? - 错误
56 64 107 == 57 64 105? - 错误
57 64 105 == 57 64 105? - 错误
什么给了???
【问题讨论】:
-
实际上,
Location似乎只是int[]的变量名:(
标签: java arrays reference contains equality