2013-10-15 112 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

就是这样!非常感谢你。 –

相关问题