I have an ArrayList of type Vertex. Vertex is my own class which contains only one data member of String type. It has a member function getName() which returns the name of the Vertex. I want to get the position in the ArrayList, if a particular string is given. I've written the below code to do it. But it always returns -1, which is the initial value. What is the problem with my code?
public int map(String vname)
{
int pos=-1;
for(int i=0;i<nodes.size();i++)
{
if(nodes.get(i).getName()==vname)
{
pos=i;
break;
}
}
return pos;
}
In the above code, nodes is an ArrayList of type Vertex.