0

This is not a duplicate, I know how to compare strings, my problems is with using substring and split methods. I am not getting my desired output I have a java project where I am reading a csv that has the first 2 columns are populated.

1st column has a path to a image of a receipt. 2nd column has the reciept number.

Problem, i want to count the number of rows where the reciept # is blank. Unfortunately, my code is ignoring the blank cell.

while ((line = br.readLine()) != null) {

       String recipetNum = null;

       String[] splitLine = line.split(",", -1);

                                  recipetNum = splitLine[2].substring(20,30).trim();

       if (!recipetNum.matches("[0-9]+") || recipetNum.length() < 8 || recipetNum == "”){



              //Add to error table

}
  • It would be much easier for you to use a library for parsing the CSV and just access the column (like Apache Commons CSV - https://commons.apache.org/proper/commons-csv/user-guide.html#Accessing_column_values_by_index) – Andrei Epure Jun 13 '17 at 12:41
  • 1
    If you know how to compare strings, why do I see `recipetNum == "”`? – MC Emperor Jun 13 '17 at 13:19
  • Was this a suggestion solution? – Joe Hopkins Jun 13 '17 at 13:26
  • It leads you in the right direction, yes. But still, my question remains unanswered. Why are you using `recipetNum == "”`? – MC Emperor Jun 13 '17 at 13:37
  • Well, I thought "" represents a empty string. – Joe Hopkins Jun 13 '17 at 13:41
  • `==` only compares the value of prìmitive types in Java. When applied to object, it compares their references. Here it will compare the value of the reference `recipetNum` with the value of the reference to the newly created object `""` – Haythem ROUIS Jun 13 '17 at 14:02

0 Answers0