-4
ArrayList<History1> hist; //i have an class History1
hist= new ArrayList<>();
public class History{
x=text.gettext;
y=text1.gettext;
public History(){
for(History hiss: hist){
if(hiss.getint()==x && hiss.getint2()==y){
System.out.println("Already exists in stack")
}
else{
hist.add(new History1(x,y))
}
}
}
}
代碼有問題,我無法找到它,這段代碼不知道給定的值是否在arraylist或不....如果它是在arraylist中沒有添加列表中的值其他它將該值添加爲歷史對象。如何知道數值是否在數組列表中?
是x和y整數?因爲你將它們設置爲text.gettext,然後與hiss.getint中的一個進行比較 – Jakob
請分享完整的代碼 –
正如這裏所寫的那樣,存在明顯的問題,使得無法肯定地說。此外,請花時間以一致的方式格式化您的代碼;不要讓我們追逐'{}'s – ChiefTwoPencils