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.