public List<List<String>> groupAnagrams(String[] strs) {
        List<List<String>> ans = new ArrayList<List<String>>();
        if (strs == null || strs.length == 0)
            return ans;
        HashMap<String, List<String>> map = new HashMap<String, List<String>>();
        for (String str : strs) {
            String key = sort(str);
            if (map.containsKey(key)) {
                map.get(key).add(str);
            } else {
                List<String> list = new ArrayList<String>();
                list.add(str);
                map.put(key, list);
            }
        }
        Iterator it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pair = (Map.Entry) it.next();
            Collections.sort((List)pair.getValue());
            ans.add((List)pair.getValue());
        }
        return ans;
    }