Reputation: 174
I have a program to read data from the csv file and manipulate the data. I read the data from the csv file using the BufferedReader readLine() method and split the line read with "," which gave me the array of String. Then, I add the trimmed element of the array to object. When I get the data from the object and compare with the same String, It shows that String are different.
public class Main {
public static void main(String[] args){
GeneralHospitalDataImpl hospitalData = new GeneralHospitalDataImpl();
File file = new File("Hospital General Information.csv");
List<Hospital> data = hospitalData.getHospitalData(file);
int i=0;
for(Hospital hospital: data){
String a = hospital.getState();
System.out.println(a);
System.out.println(a.equals("AL"));
if (a.equals("AL"))
System.out.println(hospital.getState());
i++;
if(i==5)
break;
}
}
}
Here is my output:
"AL"
false
"AL"
false
"AL"
false
"AL"
false
"AL"
false
Upvotes: 0
Views: 834
Reputation: 1664
Problem is with quotation marks. You are comparing "AL"
and "\"AL\""
and these strings aren't equal.
Upvotes: 3