1515public class AnagramsTogether {
1616
1717 /**
18- * Prints all the anagrams together from the string
19- * array {@param s}.
18+ * Prints all the anagrams together from the string array {@code strings}.
2019 * <p/>
2120 * Anagrams are words consisting of the same letters but in the same or different
2221 * order. For example, "cat" and "tac" are anagrams. Same as "god" and "dog".
2322 *
24- * @param s
23+ * @param strings
2524 */
26- private static void printAnagramsTogether (String [] s ) {
25+ private static void printAnagramsTogether (String [] strings ) {
2726
2827 // each key holds all the indexes of a anagram
2928 HashMap <String , List <Integer >> hashMap = new HashMap <>();
3029
31- for (int i = 0 ; i < s .length ; i ++) {
32- char [] chars = s [i ].toCharArray ();
30+ for (int i = 0 ; i < strings .length ; i ++) {
31+ char [] chars = strings [i ].toCharArray ();
3332 Arrays .sort (chars );
3433
3534 List <Integer > indexes = hashMap .get (String .valueOf (chars ));
@@ -42,7 +41,7 @@ private static void printAnagramsTogether(String[] s) {
4241
4342 for (Map .Entry <String , List <Integer >> entry : hashMap .entrySet ()) {
4443 for (int i = 0 ; i < entry .getValue ().size (); i ++) {
45- System .out .println (s [entry .getValue ().get (i )]);
44+ System .out .println (strings [entry .getValue ().get (i )]);
4645 }
4746 System .out .println ("------" );
4847 }
@@ -52,4 +51,4 @@ public static void main(String[] args) {
5251 printAnagramsTogether (new String []{"cat" , "dog" , "tac" , "god" , "act" });
5352 printAnagramsTogether (new String []{"cat" , "tac" , "act" , "god" , "dog" });
5453 }
55- }
54+ }
0 commit comments