由于某些原因,我的方法中的所有for-each
循环都被完全忽略,我无法弄清楚原因。这里是我的代码:对于每个循环都不执行
private static boolean notUsed(ArrayList<Integer> check, ArrayList<ArrayList<Integer>> used)
{
boolean c1 = false;
boolean c2 = true;
for (ArrayList<Integer> item : used) // Not executed
{
System.out.println("It works!");
Collections.sort(item);
Collections.sort(check);
if (check.equals(item)) c1 = true;
}
ArrayList<Integer> existing = new ArrayList<Integer>();
for (int item : check)
{
for (int exists : existing) // Not executed
{
if (exists == item)
{
c2 = false;
break;
}
else existing.add(item);
}
if (c2 == false) break;
}
if (c1 && c2) return true;
else return false;
}
我已经持续了它在过去的15分钟,看不出为什么代码拒绝与循环的内容费心。事实上,我甚至都不知道java可以在现在之前避免执行循环。我错过了明显的东西吗?
您是否尝试过在你的foreach循环变化的int整数?它们是有区别的。一个是原始的,一个是对象,所以这可能是你的问题。 – 2013-02-17 03:21:39
ArrayList的大小是多少? – afrischke 2013-02-17 03:22:23
当你说(ArrayList项目:使用)//未执行 –
smk
2013-02-17 03:23:18