File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Cattle Drive and the fly likes NaturalLanguageMultiply- Hash map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "NaturalLanguageMultiply- Hash map" Watch "NaturalLanguageMultiply- Hash map" New topic

NaturalLanguageMultiply- Hash map

yen cheong

Joined: Aug 14, 2001
Posts: 27
I'm not sure how to use this HashMap object. Do I need to create arrays like for to put these values into a Hash map object? Or do I just reuse a method in the HashMap object 28 times to place these values in? Or is there some other way? Pleas e can you help as I am not familiar with the HashMap object.
Johannes de Jong

Joined: Jan 27, 2001
Posts: 5089
Hi Yen,
Hava a look at this thread Making Hash!
Good luck
yen cheong

Joined: Aug 14, 2001
Posts: 27
Please I need some more help. I'm thinking of creating an array like in Say to contain the words for the numerics and then using a for loop to cycle this to hold these details in a hashmap.However, it seems like replication as we will then hold the values in an array and a hashmap.
Another way would be to manually repeat a method from the class hashmap 28 times to initialise the hashmap, but this also seems longwinded
Pleeeeeeeeeeeeeaaaaaaaaaaaaaaaassssssssssse help
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
It may seem longwinded but it works. The way you are talking about, with the array, uses more resources than just building the HashMap yourself. Don't know if you would get nitpicked for doing it that way, though. Do whatever is the most readable
Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
Yen Cheong,
You do not need an array nor do you need to create any logic to load the Hashmap. Simple load the Hashmap directly using its put() method. Also study the example for the assignment covering a static Vector. Instead of a static Vector you will use a static Hashmap. Your code for loading the Hashmap should look very similiar to the Vector example, except you will use a Hashmap which stores key/value pairs. The key is then used to retrieve the value from the Hashmap using its get() method.
Hope this helps
Pauline McNamara

Joined: Jan 19, 2001
Posts: 4012
Originally posted by jason adam:
Don't know if you would get nitpicked for doing it that way, though. Do whatever is the most readable

Yup, this gets nitpicked.
Using a loop to load the HashMap seemed so clever (and one way of not repeating that method 28 times), but after looking at how clear the code is when you just "put" in the keys and values directly, there's no question about which option is more readable.
Live and learn.
I agree. Here's the link:
subject: NaturalLanguageMultiply- Hash map
It's not a secret anymore!