1

please could you help me with comparing two strings with special characters in the same way as MySQL does it? For example this two strings should be equal: "Dražík" and "Drazik"

dpelisek
  • 884
  • 3
  • 13
  • 22

3 Answers3

3

Use a Collator . See Performing Locale-Independent Comparisons

Pierre
  • 34,472
  • 31
  • 113
  • 192
  • And since I'm using this comparison in equals method, do you know how to make hashcode for such a string? I mean how to get the same hash for both Dražík and Drazik. – dpelisek Aug 29 '12 at 07:09
  • Is OK to use for that myCol.getCollationKey("Dražík").hashCode() ? – dpelisek Aug 29 '12 at 07:24
1

Most probably getting the Edit Distance/ Levenshtein distance should resolve your issue. This is not an ideal solution but you may use it with significant success.

Check it Your Self

Levenshtein Distance in Java

Chathuranga Chandrasekara
  • 20,548
  • 30
  • 97
  • 138
-1

You can simply use the s.compareTo(z) function where s,z are the string names. It returns the difference between the first unmatched characters in the two strings

Arghya Chakraborty
  • 433
  • 1
  • 3
  • 12