3 Different Approaches to Single Problem || JAVA
UPVOTE THE SOLUTION IF YOU LIKE IT\n## 1st Approach\n\n\n\nclass Solution {\n    public List<List<String>> groupAnagrams(String[] s) {\n        //edge case\n   
## UPVOTE THE SOLUTION IF YOU LIKE IT\n## 1st Approach\n![image](https://assets.leetcode.com/users/images/b0c486a4-e6f2-46bb-97a3-8b18258275ae_1666922365.7035868.png)\n\n```\nclass Solution {\n    public List<List<String>> groupAnagrams(String[] s) {\n        //edge case\n        if (s.length == 1) {\n            List<String> list = new ArrayList<>(1);\n            list.add(s[0]);\n            List<List<String>> res = new ArrayList<>(1);\n            res.add(list);\n            return res;\n        }\n        List<List<String>> res = new ArrayList<>();\n        Map<String, List<String>> map = new HashMap<>();\n        StringBuilder sb = new StringBuilder();\n        for (String word : s) {\n            byte[] alphabet = new byte[26];\n            for (char c : word.toCharArray()) {\n                alphabet[c - \'a\']++;\n            }\n            for (byte freq : alphabet) {\n                sb.append(freq).append(",");\n            }\n            String key = sb.toString();\n            if (map.containsKey(key)) {\n                map.get(key).add(word);\n            } else {\n                List<String> list = new ArrayList<>();\n                list.add(word);\n                map.put(key,list);\n            }\n            sb.setLength(0);\n        }\n        return new ArrayList<>(map.values());\n    }\n}\n```\n## 2nd Approach\n![image](https://assets.leetcode.com/users/images/94dd7aa0-4153-495d-a65c-f3df3cb96a93_1666922593.1981628.png)\n```\nclass Solution {\n    public List<List<String>> groupAnagrams(String[] strs) {\n           List<List<String>> output = new ArrayList<List<String>>();\n        Map<String, List<String>> hashmap= new HashMap<String, List<String>>();\n        List<String> sortedStrings = new ArrayList<>();\n        for(String str: strs){\n            char[] charArray = str.toCharArray();\n            Arrays.sort(charArray);\n            String sorted = String.valueOf(charArray);\n            if(hashmap.containsKey(sorted)){\n                List<String> temp1 = hashmap.get(sorted);\n                temp1.add(str);\n                hashmap.put(sorted,temp1);\n            }\n            else{\n                List<String> temp = new ArrayList<>();\n                temp.add(str);\n                hashmap.put(sorted, temp);\n            }\n        }\n        return new ArrayList<>( hashmap.values());\n    }\n}\n```\n## 3rd Approach\n![image](https://assets.leetcode.com/users/images/0b3ad927-a64d-4f7a-9340-a6790344eaae_1666922547.2861967.png)\n```\nimport java.util.AbstractList;\nclass Solution {\n    private List<List<String>> result;\n\n    public List<List<String>> groupAnagrams(String[] strs) {\n        HashMap<String, List<String>> map = new HashMap<>();\n        return new AbstractList<List<String>>() {\n\n            public List<String> get(int index) {\n                if (result == null)\n                    init();\n                return result.get(index);\n            }\n\n            public int size() {\n                if (result == null)\n                    init();\n                return result.size();\n            }\n\n            private void init() {\n                for (String s : strs) {\n                    char[] count = new char[26];\n                    \n                    for (char c : s.toCharArray())\n                        count[c - \'a\']++;\n                    String key = String.valueOf(count);\n                \n                    if (!map.containsKey(key))\n                        map.put(key, new ArrayList<String>());\n                    \n                    map.get(key).add(s);\n                }\n                \n                result = new ArrayList<>(map.values());\n            }\n        };\n    }\n}\n```\n\n## IF OU REACHED TILL HERE KINDLY UPVOTE THE SOLUTION
[]