Java solution #HashMap #Unicode #Follow-up
Here is a typical solution using a hash table without considering Unicode support.\n\njava\n    public boolean isAnagram(String s, String t) {\n        if (s==n
Here is a typical solution using a hash table without considering Unicode support.\n\n```java\n    public boolean isAnagram(String s, String t) {\n        if (s==null && t==null) return true;\n        else if (s==null || t==null) return false;\n        else if (s.length() != t.length()) return false;\n        \n        Map<Character, Integer> dict = new HashMap<>();\n        for(char c : s.toCharArray()) dict.put(c, dict.getOrDefault(c, 0) + 1);\n        for(char c : t.toCharArray()) {\n            int count = dict.getOrDefault(c, 0);\n            if (count == 0) return false;\n            else dict.put(c, count - 1);\n        }\n        \n        return true;\n    }\n```\n\n-----\nIn Java, a Unicode could be represented by a single char(BMP, Basic Multilingual Plane) or two chars (high surrogate). Bascially, we can use\n- `String.codePointAt(int index)` method to get the integer representation of a Unicode (as the key in the hash table)\n- and use `Character.charCount(int code)` to count how many the characters are used there (to correctly increase our index)\n\n```java\npublic class Solution {\n    public boolean isAnagram(String s, String t) {\n        if (s==null && t==null) return true;\n        else if (s==null || t==null) return false;\n        else if (s.length() != t.length()) return false;\n        \n        Map<Integer, Integer> dict = new HashMap<>();\n        int index = 0;\n        while(index < s.length()) {\n            int charCode = s.codePointAt(index); // Get the integer representation of Unicode \n            dict.put(charCode, dict.getOrDefault(charCode, 0) + 1);\n            index += Character.charCount(charCode); // The Unicode could be represented by either one char or two chars\n        }\n        \n        index = 0;\n        while(index < t.length()) {\n            int charCode = t.codePointAt(index);\n            int count = dict.getOrDefault(charCode, 0);\n            \n            if (count == 0) return false;\n            else dict.put(charCode, count - 1);\n            \n            index += Character.charCount(charCode);\n        }\n        \n        return true;\n    }\n}\n```\n----\nIn Java 8, we can use `Charsequence.codepoints()` to simplify our code.\n\n```java\npublic class Solution {\n    public boolean isAnagram(String s, String t) {\n        if (s==null && t==null) return true;\n        else if (s==null || t==null) return false;\n        else if (s.length() != t.length()) return false;\n\n        final Map<Integer, Integer> dict = new HashMap<>();\n        s.codePoints().forEach(code -> dict.put(code, dict.getOrDefault(code, 0) + 1));\n        t.codePoints().forEach(code -> dict.put(code, dict.getOrDefault(code, 0) - 1));\n        \n        for(int count : dict.values()) {\n            if (count<0) return false;\n        }\n\n        return true;\n    }\n}\n```
['Hash Table']