title: Java Isomorphic Code
body: <p>I am kind of stuck on this java problem involving returning the number of isomorphic pairs in an array of Strings. The code I have written keeps returning incorrect number of isomorphic word pairs. </p>
  
  <p>The definition of isomorphic words is given as follows: Two words are called isomorphic if the letters in one word can be remapped to get the second word. Remapping a letter means replacing all occurrences of it with another letter. The ordering of the letters remains unchanged. No two letters may map to the same letter, but a letter may map to itself.
  For example, the words "abca" and "zbxz" are isomorphic because we can map 'a' to 'z', 'b' to 'b' and 'c' to 'x'.
  I am not inlcuding the getMap method which I call in the function. The getMap method take any string as input, and returns a map where the keys are the letters in the string, and the corresponding values are the number of times the letter appears in the string.</p>
  
  <pre><code>  public class IsomorphicWords {
    public int countPairs(String[] words) {
       Set &lt;String&gt; pairs = new HashSet&lt;String&gt;();
       for (String word:words){
           Map noOfOccurencesOfEachLetter= getMap(word);
           ArrayList&lt;Integer&gt; valuesFromFirstWord = new ArrayList&lt;Integer&gt;(noOfOccurencesOfEachLetter.values());
           Collections.sort(valuesFromFirstWord);
           java.util.List&lt;String&gt; list = new ArrayList&lt;String&gt;(Arrays.asList(words));
           list.remove(word);
           String[] oneLessWord = list.toArray(new String[words.length-1]);
           for(String secondWord:oneLessWord){
               Map secondNoOfOccurencesOfEachLetter = getMap(secondWord);
               ArrayList&lt;Integer&gt; valuesFromSecondWord = new ArrayList&lt;Integer&gt;(secondNoOfOccurencesOfEachLetter.values());
               Collections.sort(valuesFromSecondWord);
               if (valuesFromFirstWord.equals(valuesFromSecondWord)){
                  pairs.add(""+word+","+secondWord+"");
               }
               else{
                   continue;
               }
           }
  
  
       }
   return pairs.size()/2;
   public Map getMap(String word){
        HashMap&lt;String,Integer&gt; noOfOccurencesOfEachLetter= new HashMap&lt;String,Integer&gt;();
        for (int i=0;i&lt;word.length();i++){
            char letter = word.charAt(i);
            String letterInDictionary= Character.toString(letter);
            if (noOfOccurencesOfEachLetter.containsKey(letterInDictionary)==true){
                  int count= noOfOccurencesOfEachLetter.get(letterInDictionary);
                  noOfOccurencesOfEachLetter.put(letterInDictionary, count+1);
              }
             else{
                  noOfOccurencesOfEachLetter.put(letterInDictionary, 1); 
              }
        }
        return noOfOccurencesOfEachLetter;  
    }  
  }
  </code></pre>
  
  <p>I'd really appreciate any feedback you can give me on this code.</p>
  
  <p>Thanks,
  Junaid </p>