1

I have a String and i want to find in ArrayList with index or position i write code but when this is not working. itemName is one String. If condition is being true but it is not going to if block....

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(Modal)

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;
}
}
earthw0rmjim
  • 19,027
  • 9
  • 49
  • 63
Alex Mark
  • 145
  • 1
  • 7
  • after return keyword you can not write a code because after return statement code will not be run. put your code before return statement if you modify. – Divyesh Boda Aug 09 '16 at 13:10
  • It looks like the code you have should find the index from what you've shown. If it isn't going into the code block, can you show the string you are calling with and the initialization of the array list? – Aaron Davis Aug 09 '16 at 13:31
  • I guess you are somewhere confusing the items: Why is the class named "KeyValue", when its two members are named "id" and "name"? – gsl Aug 09 '16 at 13:44
  • Also why are you only searching for a matching names? What if you had two KeyValueTypes with the same name but different ids? Shouldn't you be looking for full content equality? – Aaron Davis Aug 09 '16 at 13:59
  • i need what is removed this is my solutions plz again give me this code – Alex Mark Aug 09 '16 at 15:37

0 Answers0