Is there a library out there that has a facility something like:
public static String Min(String first, String second)
If you pass it “200”/”300″ it would return “200”, for example?
I know there’s a million ways that I can write my own, so I’m really not looking for help there — just hoping to find out if it’s a wheel someone else has already invented.
Thanks in advance!
A hack frequently used in programming competitions in the absence of leading zeros is to compare string’s lengths first; if lengths are not equal, the longer string wins; otherwise, return the result of lexicographical comparing of the strings.
EDIT : Since you care mostly about re-usability of your solution, you would get the biggest “bang for the buck” if you implement your own Comparator. This would let you reuse the same implementation with standard Java classes. For example, you would be able to use your comparator with sorted maps, to do array and list sorts, binary searches, and so on.