简体   繁体   English

在java中使用unicode创建HashMap

[英]Creating a HashMap using unicode in java

I would like to create a map with japanese character. 我想创建一个日语字符的地图。 eg, 例如,

    Map<String, String> map = new HashMap<String, String>();
    map.put("あ","ア");
    map.put("え","イ");
    map.put("お","オ");
    map.put("え","エ");
    map.put("お","オ");
    String str = "あaいiうuえeおo";

Result = アaイiウuエeオo 结果=アaイiウuエオオ喔

But I want to put only unicode for japanese characters and I want to compare input string with key of map, then change it to respective value. 但我想只为日文字符添加unicode,我想比较输入字符串和map的键,然后将其更改为各自的值。 How do I change each letter of String str to unicode. 如何将String str的每个字母更改为unicode。 How do I compare each letter in a String with keys of a Map using unicode? 如何使用unicode将String中的每个字母与Map的键进行比较? If each letter exists as a key of the map, change it with respective map value. 如果每个字母都作为地图的键存在,请使用相应的地图值进行更改。 Thanks. 谢谢。

You can loop through each of the keys in your map and call String#replaceAll() for each of the respective keys and values. 您可以循环遍历映射中的每个键,并为每个相应的键和值调用String#replaceAll()。

As for turning the resulting value into unicode you can view this post: Get unicode value of a character . 至于将结果值转换为unicode,您可以查看此帖子: 获取字符的unicode值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM