Sign in to follow this  
Lothia

Searching throug Maps?

Recommended Posts

Well I was curious. I want to make a program where I have input all into maps, using the key as a String, and the Map as an Array or ArrayList. Now my question is, I want to then go through all maps and do the same process for each one in the same order they where put into the Maps. Is that at all possible and if so how? I was not sure how to call the key with out doing a cointainsKey(); or what ever that function call is. Thank you in advance. Craig

Share this post


Link to post
Share on other sites
Well, if you want to go through them in the order they were put into the map, then you wouldn't really need a string as the key would you? If all you needed the string for was to provide more information than just having an integer be the key, you could use an enum. Although...if perhaps the user was entering the string...hmm, that wouldn't work. But, just to give you my original idea, use enums like enum strings{MY_FIRST_STRING, WHATEVER_I_WANT, BREAKFAST_MMM, ANOTHER_STRING, .... } and then you could use these as your keys, since they are really just integers. This way you could start at 0 and go to the 1, then 2, then 3....although, man I do need breakfast, im sure this wouldn't work in your situation. Damn, sorry, haha

EDIT: Yeah now that I re-read your post this wouldn't work since you want input to be strings. Another thing, you wouldn't be able to use arrays since im sure you want the input to be something related to the array, right? I'm guessing you're going to need to use vectors, unless your arrays are going to be pre-made at compile-time and the user just selects one and assigns a string key to it and stores it in the map. What exactly do you want to do ?

Share this post


Link to post
Share on other sites
First, what language are you working with?

Second, why do you need to be able to look up items with a string identifyer, and why do you need to go through them in the order they're added?

Share this post


Link to post
Share on other sites
I am sorry I totally forgot to say the language.
It is Java.
Secondly i need it because the Key to the map is a word, and then the map (or what ever it is called) is an array or chars/strings each one is each of letters.
So say we ask for any combination of words in a dictionary for the word name George. It would go through and find anagrams for it until it found one. But it has to start at the beginning of the dictionary. So say the word Geo is in the dictionary. The key would be Geo, and then there would be an array for 'g', 'e', and 'o'. And then it would have to find a word that could use other letters of the word. Any ways that is what I need it for. If you have a suggestion for another way to do this I am happy to hear. I was told that using maps is faster then just putting them into an array, and that makes since because one dictionary I am using has up to 10,000 words.
So any help would be great :).


EDIT: Array/map will not be created at compile time, they will be created after the user chooses dictionary.
EDIT again: to answer the second Q, I want to be able to only go through taking the data from the dictionary and putting it into an array once, but being able to ask multiple questions. So if I went through it one at a time, that would make it have to process each time.

[Edited by - Lothia on June 8, 2007 5:19:09 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this