Comparing texts based on a locale

Hi,

if you want to sort your text based on a local like in my case it was turkish, you can use Collator class.
for example, in turkish ç character is between c and d, but if you use regular search, or use java.util.String’s compare method, ç will come after z.

so what you can do is as follows:

Collator collator = Collator.getInstance(new Locale("tr"));
return collator.compare(name,otherObject.name);

this should do the trick.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s