Linked Questions

Popular Questions

Having problem when comparing two strings

Asked by At

I'm reading a CSV file using Java. Inside the file, each row is in this format:

operation, start, end.

I need to do a different operation for different input. But something weird happened when I'm trying to compare two string.

I used equals to compare two strings. And one of the operation is "add", but the first element I fetched from the document always give me the wrong answer. I know that's an "add" and I printed it out it looks like an "add", but when I'm using operation.equals("add"), it's false. For all rest of Strings it's correct except the first one. Is there anything special about the first row in CSV file?

Here is my code:

while ((line = br.readLine()) != null) {
    String[] data = line.split(",");
    String operation = data[0];
    int start = Integer.parseInt(data[1]);
    int end = Integer.parseInt(data[2]);
    System.out.println(operation + " " + start + " " + end);

For example, it printed out add 1 3 false add 4 6 true And I really don't know why. These two add looks exactly the same.

And here is what my csv file look like: enter image description here

Related Questions