hello everyone i hope someone can help me. i want to be able to test 10 strings(some of the strings might have the same value) i want to be able test each string in turn with a loop though the hashtable. so for example if the hashtable equals string 1 extract the strings that do equal string 1 and put them inside a array list along with there key values, and then delete the ones that have been found to equal string 1, so that when i test again it will not find them again. then i want a loop to test the next string (string2) and do the same to that string and so on with the rest of the strings. could someone please help me as my code does work but it is hard coded and i need some help please. thanks for yr time. ben
Wow, you're right. That is ugly! OK, I'll make a few suggestions. First of all, why a while(hash.containsValue()) ? I'd use, "if" instead. In fact, the unconditional break at the end of the loop makes it act like an "if" structure anyway. If you ever see an unconditional break or continue ... that is one not in an "if" structure ... you know you've made a mistake. Here's another idea. How about putting the strings into an array, rather than individually named variables? Then you could use a loop and not have to cut and paste the same block of code ten times. If that approach doesn't work, how about breaking that duplicated block into a method that you call ten times. An identical or nearly identical block of code duplicated ten times is also a sure sign of a programming mistake.
here is a different way of ( hopefully ) accomplishing some of what you tried to do with the Hashtable
Not sure what you need to do in your program, but something like a dual arraylist seems more practical to me. Usually it is obvious when you've chosen the wrong data structure ( or are misusing it ) and all hands are pointing to 'misuse'! There is little functionality in my code snippet and I just typed it off the top of my head, so don't assume it will compile! But it may give you some other ideas to make your life easier! Jamie