Compare array contents accuracy algorithm
<p>I have voiceResults in an array to search for a contact:</p>

<pre><code>Ben McDonald
Ben MacDonald
Ken McDonald
Ken MacDonald
</code></pre>

<p>I have established the potentialMatches (example) in another array:</p>

<pre><code>Ben McDonald
Benjamin MacDonald
Donna McBlead //anagram
Ben Mad
abcdelmno //occurrences in alphabetical order
onmledcba //occurrences in reverse alphabetical order
completely Random
a cannon
BK Lounge
</code></pre>

<p><strong>My goal is to establish which is the most likely contact the user wanted to view.</strong></p>

<p>When looping through the two arrays, I want to use similar logic to the game <a href="http://en.wikipedia.org/wiki/Mastermind_%28board_game%29" rel="nofollow">Mastermind</a>, where I can see if a letter is 'right but in the wrong place' or 'right and in the right place'. I can then compare it to the .length() of the element and get a floating percentage of letter matches and exact position matches.</p>

<p>To do the above, I not only need to loop between elements of the arrays, I then need to break the elements up by their letters and compare those individual element letters. To establish the <a href="http://normankosmal.com/wordpress/?p=23" rel="nofollow">Mastermind</a>/<a href="http://stackoverflow.com/questions/4236906/finding-if-two-words-are-anagrams-of-each-other">anagram</a> logic, I would need to remove letters that are matches until I'm left with the letters that don't match and again compare that amount to the original length to get a percentage.</p>

<p>Looking at the example array data above, I also need to perform this in reverse and spit first names and last names.</p>

<p>For each array I started with the following:</p>

<pre><code>    ArrayList&lt;String&gt; voiceResults = new ArrayList&lt;String&gt;();
    ListIterator&lt;String&gt; itr = voiceResults .listIterator();
    Arrays.asList(voiceResults.toArray());

    while (itr.hasNext()) {
    sid = itr.nextIndex();
    element = itr.next();

    sidpass = sid.toString();
    rawpass = element.toString().toLowerCase();
    rawpass.trim();

    hcs = rawpass.split("\\s");
    hnc = hcs.length;

    if (hnc == 2) {
    fn = hcs[0]; //first name
    ln = hcs[1]; //last name
    fn = fn.replaceAll("[^a-z]", ""); //remove punctuation
    ln = ln.replaceAll("[^a-z]", "");

    }
</code></pre>

<p>I post the above, but I'm certain it's not the correct starting method.</p>

<p>Reading through many examples of anagram checks and algorithms, they vary hugely and use for and while loops, hashmaps, hash-tables, histograms, floating values etc.</p>

<p>I hold my hands up, I'm at a total loss of which is the best/fastest/most practical method to initially perform these loops, inner loops, inner element loops...</p>

<p>It would be greatly appreciated if I could have some suggestions of how the loops should be structured to begin with. </p>

<p>Further suggestions/examples/links of the letter comparisons and reverse iteration would be fantastic. Hopefully I can piece everything together then.</p>

<p>Finally, how should I store these percentages that relate to the elements??</p>

<p>I thank you in advance.</p>

<p>PLEASE NOTE: Although the example data may suggest otherwise, I have already used a loop and .contains() .matches() etc etc. </p>
