简体   繁体   中英

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

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. How do I change each letter of String str to unicode. How do I compare each letter in a String with keys of a Map using unicode? 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.

As for turning the resulting value into unicode you can view this post: Get unicode value of a character .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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