aspose file tools*
The moose likes Java in General and the fly likes help with some code. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "help with some code." Watch "help with some code." New topic
Author

help with some code.

ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
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
Norm Miller
Ranch Hand

Joined: May 21, 2002
Posts: 56
Maybe you could show us what you have done so far. Use UBB code tags to bracket the code.
ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
this is what i have done so far it works how i want it to but it is just so ugly
thanks
ben

(edited by Cindy to close the code block - although now it is SOOOO wide . . . )
[ December 13, 2002: Message edited by: Cindy Glass ]
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

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.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with some code.