2012-08-14 51 views
-1

我有一個int n選擇一個隨機數。每次我將n保存在arraylist數組中。現在我想比較一下,如果int n等於兩個最後的隨機數。例如,如果我們有2 - 3 - 5- 3,它應該選擇3作爲重複的int。我應該比較它們嗎?Android ArrayList值

if(n == array.size()-2) { 
} 

它不這樣工作。哪裏有問題?

回答

2
if(n == array.get(array.size()-2)) { 
//some code 
} 
1

去年兩個整數比較,使用:

if(n == array.get(array.size()-2) || n == array.get(array.size()-1)) { 
    //do the Logic here if they are Same 
}