I'm trying to display Car from fleet ArrayList using user input. Unfortunately I'm not sure how to go about it. I have found few examples online but cannot make them work. I have incorporated following method:
void findRegNo(String reg){
boolean exist=false;
for(int i=0;i<this.fleet.size();i++){
if(this.fleet.get(i).getRegNo() == reg){
exist=true;
break;
}
}
if(exist) {
System.out.println("!!!!!");
} else {
System.out.println("xxx");
}
}
At the moment the result is always: xxx so the code does not find any match. That function is placed in my container class, I was thinking that maybe it supposed to be in different location.
These are variables of Car class:
public class Car {
//defining variables
String regNo;
String model;
double mileage;
String.equalsto compare strings