If you want to compare the String value stored in a Vector with another String value then its for you. I have given here a better Comparison solution to compare the value in
public MainClass() {
Vector vec=new Vector();
vec.add(“Jhony”);
String name=”Jhony”;
/*********************Better Way***************************/
if(vec.get(0).toString().trim().equalsIgnoreCase(name))
{
System.out.println(“First Try Name Match”);
}
else
{
System.out.println(“First Try Name Not Matched”);
}
/*********************End of: Better Way***************************/
/*********************Not so Better Way***************************/
if(vec.get(0).toString()==name)
{
System.out.println(“Second Try Name Match”);
}
else
{
System.out.println(“Second Try Name Not Matched”);
}
/****************End of : Not so Better Way**********************/
}
public static void main(String[] args) {
MainClass x=new MainClass();
}
It is better to just use the Vector contains method
vec.contains(name)
LikeLike