public List<String> anagrams(final String[] strs) {

        final Map<String, LinkedList<String>> map = new HashMap<String, LinkedList<String>>();

        // sort each string, and store in a map
        for (int i = 0; i < strs.length; i++) {
            final String str = strs[i];
            if (str.isEmpty()) {
                continue;
            }
            final char[] c = str.toCharArray();
            Arrays.sort(c);
            final String sorted = String.valueOf(c);

            if (map.containsKey(sorted)) {
                map.get(sorted).add(str);
            } else {
                final LinkedList<String> linkedList = new LinkedList<String>();
                linkedList.add(str);
                map.put(sorted, linkedList);
            }
        }

        final List<String> list = new LinkedList<String>();
        for (final LinkedList<String> strings : map.values()) {
            list.addAll(strings);
        }

        return list;
    }