public static void find_anagrams(ArrayList<String> dictionary) {
    // Get the sorted string and then insert into hash table.
    HashMap<String, ArrayList<String>> hash = new HashMap<String, ArrayList<String>>();
    for (String s : dictionary) {
      char[] sorted_ca = s.toCharArray();
      // Use sorted string as the hash code.
      Arrays.sort(sorted_ca);
      String sorted_str = new String(sorted_ca);
      if (!hash.containsKey(sorted_str)) {
        hash.put(sorted_str, new ArrayList<String>());
      }
      hash.get(sorted_str).add(s);
    }

    for (Map.Entry<String, ArrayList<String>> p : hash.entrySet()) {
      // Multiple strings with the same hash code => anagrams.
      if (p.getValue().size() >= 2) {
        // Output all strings.
        System.out.println(Arrays.toString(p.getValue().toArray()));
      }
    }
  }