• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NaturalLanguageMultiply- Hash map

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yen,
Hava a look at this thread Making Hash!
Good luck
 
yen cheong
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic