If you go and ask a mathematician, you will be told that sets do not support sorting or order as a default. So the iteration order of an ordinary set is unpredictable, and sets supporting some sort of predictable iteration order are special cases.
Dana Ucaed wrote:. . . put into set but without sorting: . . .
Carey Brown wrote:How about the equals() method also accepting an instanceof String?
Rob Spoor wrote:Which is why you can't use equalsIgnoreCase in an equals method, because there is no matching hash code method. I prefer the toLowerCase solution. If you want to prevent the creation of new Strings you can create some utility methods (e.g. equalsLowerCase(String s1, String s2), hashCodeLowerCase(String s) and possibly even compareToLowerCase(String s1, String s2)).
Carey Brown wrote:I was looking at Java's source code for equalsIgnoreCase() and they do an interesting thing, they compare the chars to see if they're equal, if not then they compare the lower case of the chars to see if they're equal. if not, they make yet another test of comparing the upper case of the chars. This leads me to think that even String#toLowerCase() is not symetrical to String#toUpperCase() leading me to think that computing a hash code based on a String returned from toLowerCase() might have an issue in some languages. How wide spread is this issue? I couldn't say but I doubt it will impact me, not a good stance for a production level programmer, but what's a body to do?