Word ladder finding class I have a class that I'm using to find the shortest word ladder between two words. Each "Step" in that ladder is returned as a String element in a LinkedList. If it can't find one, it returns an empty LinkedList. The class is only intended to work with capital letters.

A step can only be formed from a word in the HashSet&lt;String&gt; dictionary variable.

I haven't made anything like this before, and I'm posting here because I'd appreciate help making it run faster and advice regarding how to make the code itself more easily read by other humans.

public class WordLadder {

private HashSet&lt;String&gt; dictionary;

public WordLadder(HashSet&lt;String&gt; dictionary) {

   this.dictionary = dictionary;
}

/**
 * This method finds the shortest word ladder between two words and returns
 * it as a LinkedList of Strings.
 *
 * @return LinkedList of Strings.
 */
@SuppressWarnings("unchecked")
public LinkedList&lt;String&gt; findLadder(String input) {

   // this method relies on deleting entries from a HashSet
   HashSet&lt;String&gt; tempDict = (HashSet&lt;String&gt;) this.dictionary.clone();

   // create LinkedLists 
   LinkedList&lt;Integer&gt; distances = new LinkedList&lt;&gt;();
   LinkedList&lt;LinkedList&lt;String&gt;&gt; ladders = new LinkedList&lt;&gt;();
   LinkedList&lt;String&gt; words = new LinkedList&lt;&gt;();

   // split the input line into the starting and ending words
   String startWord = input.substring(0, input.indexOf(" "));
   String endWord = input.substring(input.indexOf(" ") + 1);

   // holds the shortest ladder found
   LinkedList&lt;String&gt; shortestLadder = new LinkedList&lt;&gt;();

   words.add(startWord);
   distances.add(1);

   ladders.add(new LinkedList&lt;&gt;(Arrays.asList(startWord)));

   while (!words.isEmpty()) {
      Integer distance = distances.pop();
      LinkedList&lt;String&gt; ladder = ladders.pop();
      String word = words.pop();

      // has the shortest ladder been found?
      if (word.equals(endWord)) {
            shortestLadder = ladder;
      }

      for (int i = 0; i &lt; word.length(); i++) {

         char[] currCharArr = word.toCharArray();

         for (char c = 'A'; c &lt;= 'Z'; c++) {
            currCharArr[i] = c;
            LinkedList&lt;String&gt; currentPathQueueTemp = new LinkedList&lt;&gt;(ladder);

            String newWord = new String(currCharArr);

            if (tempDict.contains(newWord)) {
               words.add(newWord);
               ladders.add(currentPathQueueTemp);
               tempDict.remove(newWord);
               distances.add(distance + 1);
               currentPathQueueTemp.add(newWord);
            }
         }
      }
   }

   return shortestLadder;
}

}
Fist of all, the code doesn't work. here's my test method. I get an empty response.

public static void main(String... args) {

    HashSet&lt;String&gt; dictionary = new HashSet&lt;&gt;();
    dictionary.add("abcd");
    dictionary.add("abce");
    dictionary.add("abcf");
    dictionary.add("abcg");
    dictionary.add("abch");
    dictionary.add("abxd");
    dictionary.add("abxh");

    WordLadder wd = new WordLadder(dictionary);
    System.out.println(wd.findLadder("abcd abch"));

}


However, assuming you fix this, here is my review


API definition: the api you chose is counter-intuitive. why not accept two string words?
code to the interface: if you meant words to be a LIFO stack, use the Stack interface of push() and pop().  there are two reason for that: one is that it makes the usage of words clearer to another human. more importantly - how do you that LinkedList add() is doing the same as push()? 
the method violates the single responsibility principle. it is parsing the input, it searches for a word in the dictionary and all the other stuff. what if you wanted to have another data structure for the dictionary? or put it in a DB?