File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes searching for possible word Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "searching for possible word" Watch "searching for possible word" New topic

searching for possible word

Gary Goldsmith
Ranch Hand

Joined: Mar 06, 2007
Posts: 30
Hi, I have a dictionary loaded into a hashmap, and I have a partial decrypted word. What I want to know is how do I enter a string (e.g. atteJFtiHU) lowercase letters are known letters and uppercase are still crypted letters. And search the dictionary on possible matches. Maybe the first question should be is a hashmap a good way to go about this or would a linkedlist be better? So I want to say here's my string 'atteJFtiHU' and have it return saying this is the list of possible matches e.g. 'attempting'. Any advice would be greatly received.
Gary Goldsmith
Ranch Hand

Joined: Mar 06, 2007
Posts: 30
This is what I have so far, but returns a nullPointerException, and I'm not sure it's going to do what I expect it to.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
dictionary.get is not doing what you think it does. Read the javadoc for Map/HashMap carefully.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

Since your dictionary map contains entries that have equal keys and values, you chould switch to a Set<String> instead, using HashSet<String> as implementation:

How To Ask Questions How To Answer Questions
Gary Goldsmith
Ranch Hand

Joined: Mar 06, 2007
Posts: 30
Thank you, that was a big improvement on my old code, the only thing is it's not able to work out the partially decrypted word, if I say:
String strToCompare = "attempting";
Then it returns it from the set, but if I pass in:
String strToCompare = "atteJFtiHU";
Then nothing happens, how can I search the Set for a word that is a possible match to "atteJFtiHU" - lowerCase letters are letters that have been worked out uppercase are letters that haven't been worked out yet.
Gary Goldsmith
Ranch Hand

Joined: Mar 06, 2007
Posts: 30
Thank you for your help, I have now worked out the problem

Thanks for your help.
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
[Gary Goldsmith:]   Thank you for your help, I have now worked out the problem

Well can we see the code ? Some others are working on this same problem (me) and a fast, efficient decryption approach is always of interest in the matter - such as maintaining a precompiled TreeSet of Patterns for working through Collections of junk mail looking for the markers that Oscar De Grouch should have a chance at.
[ November 25, 2007: Message edited by: Nicholas Jordan ]

"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Originally posted by Rob Prime:

I think you're having a regex issue. I think you want your string to compare to have a '.' (period) where you need to match any character. Thus:

[ November 26, 2007: Message edited by: Bill Shirley ]

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
I agree. Here's the link:
subject: searching for possible word
jQuery in Action, 3rd edition