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
  • 736
  • 3
  • 12
  • 20

3 Answers3

3

Use a Collator . See Performing Locale-Independent Comparisons

Pierre
  • 33,089
  • 29
  • 109
  • 185
  • 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
  • 19,894
  • 28
  • 96
  • 137
-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
  • 423
  • 1
  • 3
  • 12