I am trying to learn more about using HashMaps in java. I would like to write a program that searches through a list of jumbled words from one text file and returns the unscrambled word(s) from another text file. Any suggestions how to do this?
coolsport04
0
Newbie Poster
Recommended Answers
Jump to PostThis will really depend on what you're trying to do.
A hashmap will be beneficial when you already know what things belong together (key, value pairs).Will the program need to unscramble (or scramble) the words?
Jump to PostOK, so in what capacity do you want to use the hash table?
Do you want it to hold both the scrambled AND the unscrambled word, so when it is presented with a scrambled word, it will just return the "value" of the unscrambled word?
...or will you try to …
Jump to Post...so, something like this, but getting the values from a file?
import java.util.*; import java.io.*; class Hashtest { public static void main(String[] args) { Hashtable<String, String> map_s2sData = new Hashtable<String, String>(); map_s2sData.put("addej", "jaded"); map_s2sData.put("ahicryrhe", "banana"); map_s2sData.put("alvan", "naval"); map_s2sData.put("baltoc", "cobalt"); map_s2sData.put("anaban", "banana"); if(map_s2sData.containsKey("anaban")) { System.out.println(map_s2sData.get("anaban")); } } }
Jump to PostWhich technique do you use for reading files?
All 14 Replies
thines01
401
Postaholic
Team Colleague
Featured Poster
coolsport04
0
Newbie Poster
thines01
401
Postaholic
Team Colleague
Featured Poster
coolsport04
0
Newbie Poster
thines01
401
Postaholic
Team Colleague
Featured Poster
coolsport04
0
Newbie Poster
thines01
401
Postaholic
Team Colleague
Featured Poster
coolsport04
0
Newbie Poster
thines01
401
Postaholic
Team Colleague
Featured Poster
coolsport04
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
coolsport04
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
thines01
401
Postaholic
Team Colleague
Featured Poster
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.