如何从原样检索hashmap中的数据,而无需在java中删除转义字符

时间:2016-04-04 11:59:17

标签: java hashmap

从hashmap读取时删除了char,

import java.util.*;
// our main class becomes a file but the main method is still found
public class HelloWorld
{

public static void main (String[] args) throws java.lang.Exception
{
    // your code goes here
    HashMap<Integer,String> map = new HashMap<Integer,String>();
    map.put(1,"hai");
  map.put(2,"h\"ai");
Iterator entries = map.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
Integer key = (Integer)entry.getKey();
String value =(String) entry.getValue();
System.out.println("Key = " + key + ", Value = " + value);
}
}
}

 Output:  Key = 1, Value = hai
          Key = 2, Value = h"ai
 Expected: Key = 1, Value = hai
          Key = 2, Value = h\"ai

它不是关于数据打印,我的意思是从地图中提取值时应该获得相同的状态。我做了调试 我能够在地图中看到正确的数据。当我执行getValue时,它的输出字符串没有&#34; \&#34;炭。

注意:它&#39;如果我们打印System.out.println(&#34; hahs \&#34; dk&#34;),请不要打印数据; 它会给hahs&#34; dk。我担心运行时值

请一些人可以帮忙或建议一些链接。 谢谢

0 个答案:

没有答案