File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "NaturalLanguageMultiply- Hash map" Watch "NaturalLanguageMultiply- Hash map" New topic
Author

NaturalLanguageMultiply- Hash map

yen cheong
Greenhorn

Joined: Aug 14, 2001
Posts: 27
Hello
I'm not sure how to use this HashMap object. Do I need to create arrays like for Say.java 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.
Thanks
Yen
Johannes de Jong
tumbleweed
Bartender

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

Joined: Aug 14, 2001
Posts: 27
Hi
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
Yen
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
Jason
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
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
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.
Pauline
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NaturalLanguageMultiply- Hash map
 
Similar Threads
Hashmap operational upper bounds.
null values in hash map
Setting ResultSet into an ArryList
HashMapping
How To Get Rid Of java.util.ConcurrentModificationException?