Hi, i am prettry sure that my idea is correct, the principle being to turn the parameter to a char array and the word in the dictionary to a char array, sort them alphabetically then compare, if the same then woot :d
however i am aware that the for each loop in this instance is inappropriate as it will continually change the value of myAnagramTwo until it gets to the end
please can i have
hints as to a better way of assigning myAnnagramTwo to a char array in order to compare them?
thanks everyone
(no solutions please as my teacher will go crazy)
public ArrayList<String> anagrams(String word)
{
ArrayList<String>anagram;
anagram = new ArrayList<String>();
char [] myAnagram = word.toCharArray();
char [] myAnagramTwo = null;
for (String otherWord : dictionary){
myAnagramTwo = otherWord.toCharArray();
}
Arrays.sort(myAnagramTwo);
Arrays.sort(myAnagram);
if (myAnagram.equals(myAnagramTwo)){
anagram.add(word);
}
return anagram;
}
}