Share my short JAVA solution
\n    public List<List<String>> groupAnagrams(String[] strs) {\n        if (strs == null || strs.length == 0) return new ArrayList<>();\n        Map<String, Lis
```\n    public List<List<String>> groupAnagrams(String[] strs) {\n        if (strs == null || strs.length == 0) return new ArrayList<>();\n        Map<String, List<String>> map = new HashMap<>();\n        for (String s : strs) {\n            char[] ca = s.toCharArray();\n            Arrays.sort(ca);\n            String keyStr = String.valueOf(ca);\n            if (!map.containsKey(keyStr)) map.put(keyStr, new ArrayList<>());\n            map.get(keyStr).add(s);\n        }\n        return new ArrayList<>(map.values());\n    }\n```\n\nInstead of sorting, we can also build the key string in this way. Thanks @davidluoyes for pointing this out.\n\n```\n    public List<List<String>> groupAnagrams(String[] strs) {\n        if (strs == null || strs.length == 0) return new ArrayList<>();\n        Map<String, List<String>> map = new HashMap<>();\n        for (String s : strs) {\n            char[] ca = new char[26];\n            for (char c : s.toCharArray()) ca[c - \'a\']++;\n            String keyStr = String.valueOf(ca);\n            if (!map.containsKey(keyStr)) map.put(keyStr, new ArrayList<>());\n            map.get(keyStr).add(s);\n        }\n        return new ArrayList<>(map.values());\n    }\n```
['Java']