I have a private class that I want to be able to find the shortest Hamming Distance between two Strings of equal length in Java. The private class holds a char[]
and contains a method to compare against other char arrays. It returns true if there is only a hamming distance of one.
Is there a way to make the isDistanceOne(char[])
method go any faster?
private class WordArray { char[] word; /** * Creates a new WordArray object. * * @param word The word to add to the WordArray. */ private WordArray(String word) { this.word = word.toCharArray(); } /** * Returns whether the argument is within a Hamming Distance of one from * the char[] contained in the WordArray. * * Both char[]s should be of the same length. * * @param otherWord The word to compare with this.word. * @return boolean. */ private boolean isDistanceOne(char[] otherWord) { int count = 0; for(int i = 0; i < otherWord.length; i++) { if (this.word[i] != otherWord[i]) count++; } return (count == 1); } }
The post Very fast method to find hamming distance between two Strings of equal length in Java? appeared first on 100% Private Proxies - Fast, Anonymous, Quality, Unlimited USA Private Proxy!.