public ArrayList<String> anagrams(String[] strs) {
        HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
        for (int i = 0; i < strs.length; i++) {
            String crt = strs[i];
            char[] array = crt.toCharArray();
            Arrays.sort(array);
            String sorted_str = String.valueOf(array);
            if (!map.containsKey(sorted_str)) {
                map.put(sorted_str, new ArrayList<String>());
            }
            map.get(sorted_str).add(crt);
        }
        
        ArrayList<String> result = new ArrayList<String>();
        Iterator<Map.Entry<String, ArrayList<String>>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            ArrayList<String> list = it.next().getValue();
            if (list.size() > 1) {
                result.addAll(list);
            }
        }
        return result;
    }