我有一个String
,我希望在ArrayList
中找到索引或位置,我会编写代码,但是当它不起作用时。 itemName
是一个String
。如果条件是true
,但是如果阻止它就不会......
public int getIndex(String itemName)
{
for (int i = 0; i < kvArrayList.size(); i++)
{
KeyValueType kv = kvArrayList.get(i);
if (kv.getName().equalsIgnoreCase(itemName))
{
return i;
//if condition is true but not coming here
}
}
return -1;
}
KeyValueType.class(模态)
import java.io.Serializable;
public class KeyValueType implements Serializable{
private static final long serialVersionUID = 6121835779951930267L;
String id;
String name;
public KeyValueType(String id, String name) {
this.id = id;
this.name = name;
}
@Override
public String toString() {
return name.toString();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}