Java hashmap cannot find existing entry

tom :

I am running into a very weird problem: I wrote a CSV parser where it reads the first row as headers, then creates a map where key is the header and value is the values in subsequent rows.

The issue is the map cannot seem to retrieve the value of the header of the first column. As seen here: enter image description here

as you can see, "abc" is inside the HashMap entry #23, but when I am retrieving it, it would show as null.

I think it has something to do with my CSV file but why is the map entries showing up correctly on debugger but cannot retrieve?

my CSV file looks like this:

abc,Data Source,Entity,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24 NA,source1,entity1,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124

John Bollinger :

The only plausible explanation for the debugger results you observe is that the first column header is not actually "abc". It likely has one or more additional, non-printing characters within. These do not print, naturally, in the debugger's list of the map's contents, but they are nevertheless there, so indeed the key "abc" is not present in the map. It is actually something like "<some_non-printing_character>abc". Alternatively, it may be that you have different characters that are rendered the same on your display. Either way, examine the input file with a hex editor to see the truth.

The column in question being the first, a likely candidate for an extra character is a Unicode BOM, U+FEFF, appearing as the first character of the file. Some text editors will insert such a character as a magic number marking files as being encoded in UTF-8, though in fact UTF-8 does not require that, and assigns no significance to such a character other than as itself.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=112920&siteId=1