• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jumbles and Hashmap  RSS feed

 
john kidwell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I need some help. I made this code to look through a jumbles.txt and a dictionary.txt and match the words together that were similar. Now my teacher wants me to change my code so that it uses hashmaps. Do you know how i could go about doing this? Here's my code

 
Emil Jennings
Ranch Hand
Posts: 75
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into the Java collections. Lists, Sets, and Maps are your friend. Where you currently use String arrays you can substitute that with a collection. A map is a key value pair that does not allow duplicate keys. Also, unlike arrays, collections don't need to be coded with bounds, they "grow" as needed (see the API).

And if any of this makes no sense, ask and I'll try to explain better.
 
Ryan Tracy
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The important pieces to HashMap are put and get. If i need to store something I 'put' it in the Map. If I need something from the Map I 'get' it. all Objects have a key whether you are putting them in or getting them out. The best place to start would be reviewing the API however the API doesn't always tell you how to use them. here is some sample code below on its usage.

Put them in to map


Get them out of map


Alternatively
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!