2013-10-15 64 views
0

嘿,我正在爲一個項目輸入部門信息。這些信息包括名稱,縮寫,位置和成員數量。我有第一個類接受8個參數,(字符串,字符串縮寫,字符串,int,int,int,int,int,double)。查找ArrayList中是否存在字符串

它被添加到一個ArrayList中,我無法測試以查看這些類中是否存在字符串縮寫。

我有什麼作爲的方法是:

private ArrayList<DeptInfo> dept = new ArrayList<DeptInfo>(); 

    public boolean deleteDeptInfo(String abbrev) { 

    boolean result = false; 
    int index = -1; 
    for (DeptInfo test : dept) { 
    if (test.getAbbrev() == abbrev) { 
     index = dept.indexOf(test); 
     break; 
    } 
    } 

    if (index >= 0) { 
    dept.remove(index); 
    result = true; 
    } 
    return result; 
} 
+0

最新的麻煩? – JungJoo

回答

0

我敢打賭,它在if條件的說法,當你比較,你必須使用.equal方法字符串。

+0

就是這樣!非常感謝你。 –

相關問題