0

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
0

1 Answer 1

3

Problem is with quotation marks. You are comparing "AL" and "\"AL\"" and these strings aren't equal.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.