class Solution { public List<List<String>> groupAnagrams(String[] strs) { Map<String,List<String>> map=new HashMap<String, List<String>>(); for(String str: strs) { char[] arr=str.toCharArray(); Arrays.sort(arr); String key=new String(arr); if(!map.containsKey(key)) map.put(key, new ArrayList<String>()); map.get(key).add(str); } return new ArrayList<List<String>>(map.values()); } }