Vector indexOf
hi, I've a problem with a Vector function: indexOf
It should return the index of frist element found in the vector using "equals" to compare the object:
well, I've wrote a little program to test this fucntion, but it don't works well, why!!?
import java.util.Vector;
publicclass test{
publicstaticvoid main(String[] args){
Vector<MyString> vet =new Vector();
vet.add(new MyString("zero"));
vet.add(new MyString("one"));
vet.add(new MyString("two"));
System.out.println(vet.elementAt(1).equals("one"));//prints true
System.out.println(vet.contains("one"));// prints false
}
}
now, MyString code:
package p1;
publicclass MyString{
public String name;
public MyString(String nome){
name = nome;
}
publicboolean equals(Object o){
if ( ((String)o).equals(name) )returntrue;
returnfalse;
}
}

