• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Collator / CollationKey objects for String comparision  RSS feed

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

As per the javadoc, the Collator class enables locale-specific string comparison. Though the javadoc describes the use of the strength property in string comparison, being locale dependent, I did not fully understand how it works and therefore asking in this forum.

My questions are:

a) How does the strength property manipulate the CollationKey(s) - representing the respective strings & generated from the same Collator object - to return different results of the string comparison
(given that strings are immutable), as shown in the sample program and output below.

b) Is using Collator class a more efficient way to compare strings.



FOR THE DEFAULT LOCALE (WITHOUT SETTING THE STRENGTH PROPERTY)


Output:


FOR LOCALE SET TO U.S (STRENGTH SET TO PRIMARY)


Output:


STRENGTH SET TO SECONDARY


Output:


STRENGTH SET TO TERTIARY


Output:


STRENGTH SET TO IDENTICAL


Output:


Would much appreciate response from the forum experts / members.

Thanks,
Sudhir

 
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some levels of the strength govern features which English does not have. For example, in my language, letters "e" and "é" are considered equal when collating with certain strengths, but non-equal with others. You could try them with a locale set to cs_CZ.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!