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 ?

Recommended Answers

All 3 Replies

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.

Thank you. This might actually help. I am gonna give it a try.

Member Avatar for iamthwee

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.