My main idea is to find an algorithm ( Java ) that takes the random letters which someone has typed in a JoptionPane for instance and then instantly by pressing "Find words" i would like the program to derive all those words that match my letters from a dictionary stored in a .txt file.

I am struggling to find that algorithm.

For example:

Take into consideration that we got the following letters in a Scrabble match:

a , o ,p, t, e, z, e, w

I would like to find a java code or at least an algorithm in order to find from an english dictionary .txt file all the words that have those letters but not anything else. if I type " a, p, p" I want to have as a result the word "app" and not (app"s"). So ... to sum up, how can i compare those letters from words stored in a .txt file and as a result get specific words that match in my given letters ?

4 Years
Discussion Span
Last Post by iamthwee

you mean to find all words that have only letters in your Scrabble letters?

well, you can read your textfile in a collection.
then write an algorithm that checks for each word, for how much of the letters you have, there is an occurence, for instance, "app" would give 3 (1a and 2p).
next, you check the result of that check with the length of the word. if they are equal, you have a valid word.
if the length is longer, it means you have chars there that are not in your Scrabble letters.


You might also want to use a hashmap to store the letter values. For example, obscure letters like 'q' and 'z' would give more points. Then find the letter points total and return the largest.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.