I need to find car
element in ArrayList. The ArrayList data like this
{ [1,mobile,5000]
[2,car,50000]
[3,bike,20000] }
and classes are
//pro.java
import java.util.*;
public class Pro{
private int id;
private String name;
private int price;
public String toString(){
return id+" "+name+" "+price;
}
//getter & setter methods
}
and the search code is like this
//Product.java
System.out.println("enter name you want to search");
name = scanner.next();
Iterator it=al.iterator();
while(it.hasNext()){
if(it.next() == name){
System.out.println("Yes found");
}
else{
System.out.println("Not Found");
}
}
it
is the iterator reference object and al
is the ArrayList reference object.
the search is always return Not found but the element what I find is exist. How to fix it in order to return FOUND? Please help me with the appropriate code Thank's.