Q:

Best data structure for dictionary in Java (and also Python)

Here is my requirement: 

Input: Random String of sufficiently long ex: fdjhkajajkfdj
Output: fdj has a 2 occurences and separated by x chars

I want to put all three letter words in an array and check if they are the same
Eg: 
a[0] = fdj
a[1] = djh
a[2] = jhk
a[3] = hka
a[4] = kaj
.
.
.
a[n] =fdj

My answer is a[0] and a[n] matches, may be more than 2 occurances.
Question: So what kind of array should I use which is optimal in this situation. I am using Java (and also python). I was thinking of Dict.

A:

In Java you could use the Map interface ( http://download.oracle.com/javase/1.4.2/docs/api/java/util/Map.html )
I would use HashMap so that the key is the 3 letter word and the value is the count of occurances. Here's some sample pseudo code
HashMap<String, int> wordCountMap = new HashMap<String, int>();
for(....) // for each 3 letter word in the input
{
    String word = ...; // current three letter word
    if(wordCountMap.containsKey(word))
        wordCountMap.put(word, wordCountMap.get(word)++);
    else
        wordCountMap.put(word, 1);
}

Then you can loop through the key/value pairs and return their occurance count.
To return the number of characters between the words, you can do this separately after counting the occurances by using String manipulation (see String.indexOf). Pseudo code for this is....
String orginalInput = "fdjhkajajkfdj";
String word = "fdj";
int firstOccurance = originalInput.indexOf();
int secondOccurance = originalInput.indexOf(firstOccurance+1);
int charsInBetween = secondOccurance - firstOccurance - 3; // difference in indices minus length of word

