Java map returns null for current key

I have a very unusual problem.
Basically, I am trying to get the value associated with a key from a string map to strings.
I know that the key that I use is present; I use the same line that I used to enter it!

I print statements all over my code, and this is the case when I have ... Here is my characterDictionary

{thusChar=∴, spaceChar= , plusChar=+, equalsIndent=#, multiplyChar=×, equalsChar==, newlineChar=\n, divideChar=÷, subjectChar=:, variableIndent=@}

The most recent "variableIndent" key is the problem!
Here is the code ...

System.out.println  (   characterDictionary.get("variableIndent") );

which incorrectly displays: null

I checked, double checked and tripled my code.
There is no difference between the "variableIndent" key and the string argument characterDictionary.get("variableIndent"), but it behaves as if this key were missing.

I can guarantee that this key is present, and that the two lines are identical.
All other elements (those that I checked, about 3 so far) of the dictionary are extracted as usual. Why does "variableIndent" play with the value "@" with it?

You may notice that the dictionary contains non-ASCII characters, such as "thatChar". Could this be related?

Thanks
(This seems like a very simple and trivial problem, as if I made some kind of pathetic stupid mistake, but still I just can't solve it!)

EDIT:

, - .
get. , java , .
UTF-8, java Eclipse.
. ?

!

EDIT:

, .
UTF-8, ...

variableIndent,@
equalsIndent,#
spaceChar, 
newlineChar,\n
multiplyChar,×
divideChar,÷
plusChar,+
equalsChar,=
subjectChar,:
thusChar,∴

, ArrayList<String>, :

private static ArrayList<String> readLinesFile(String ResourceFile)  {
    ArrayList<String> Lines = new ArrayList<String>();
        try{
            InputStream fstream = FileManager.class.getResourceAsStream(ResourceFile);
            BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
            String strLine;
            while ((strLine = br.readLine()) != null)  {
                Lines.add(strLine);  } 
            in.close();  }
        catch (Exception e)  {
            System.out.println("Error: " + e.getMessage());  } 
        return Lines;  }

. ArrayList , "," ( , ) .

private static Map<String, String> generateBaseUnits_Characters_Prefixes(ArrayList<String> FileContent)  {
    Map<String, String> BaseUnitsCache = new HashMap<String, String>();
    ArrayList<String> currentLine;
    for (int i=0; i<FileContent.size(); i++)  {
        currentLine = MiscellaneousFunctions.splitString(FileContent.get(i), ",");
        BaseUnitsCache.put(currentLine.get(0), currentLine.get(1)); }
    return BaseUnitsCache;  }

, .
, , .

public static String variableIndentKey = "variableIndent";
public static String equalsIndentKey = "equalsIndent";
public static String spaceCharKey = "spaceChar";  
public static String newlineCharKey = "newlineChar";
public static String multiplyCharKey = "multiplyChar";
public static String divideCharKey = "divideChar";  
public static String plusCharKey = "plusChar";
public static String equalsCharKey = "equalsChar";  
public static String subjectCharKey = "subjectChar";
public static String thusCharKey = "thusChar";

:

" " . keySet , "null".
( variableIndent. variableIndent , equalsIndent ..)

!?
?! .

!

+5
6

UTF-8, UTF-8 . (UTF-8 BOM 0xEF, 0xBB, 0xBF "variableIndent" ) . http://en.wikipedia.org/wiki/Byte_order_mark

+6

(, , ), , UTF-8. , . Inherited from container Oher: UTF-8

+1

. , - , .

String data = "{thusChar=∴, spaceChar= , plusChar=+, equalsIndent=#, multiplyChar=×, equalsChar==, newlineChar=\\n, divideChar=÷, subjectChar=:, variableIndent=@}";
Map<String, String> map = new LinkedHashMap<String, String>();
for (String keyValue : data.substring(1, data.length() - 1).split(", ")) {
    String[] parts = keyValue.split("=", 2);
    map.put(parts[0], parts[1]);
}
System.out.println("variableIndent is " + map.get("variableIndent"));

variableIndent is @

for(String key: map.keySet())
   System.out.println("'"+key+"'= "+map.get(key));
0

for (String key : characterDictionary.keySet() ) {
System.out.println(key);
}

for ( String value :  characterDictionary.values() ) {
System.out.println(value);
}

P.S: .

0

, , , , .

getBytes(), ( , )

getChars(), charAt() char

  • char .

, . ?

, DataInputStream .

InputStream fstream = FileManager.class.getResourceAsStream(ResourceFile);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));

Java DataInputStream : " Java - . , ". DataOutputStream , . , InputStream InputStreamReader. :

InputStream fstream = FileManager.class.getResourceAsStream(ResourceFile);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));

2

, , 3 ,

BaseUnitsCache.put(currentLine.get(0), currentLine.get(1));

to

BaseUnitsCache.put(currentLine.get(0).trim(), currentLine.get(1).trim());
0

...

Map<String, String> map = new LinkedHashMap<String, String>();


for (Map.Entry<String, String> mp : map.entrySet()){


  System.out.println("Key: "+mp.key()+"::"+"Value: "+mp.value());


}
0

All Articles