Will comparteTo() method of the String class work with internationalization(diff locale)? - Manish
Maulin Vasavada
Ranch Hand
Joined: Nov 04, 2001
Posts: 1865
posted
0
Hi Manish
As far as I know compareTo() just do character by character comparision like, int len1 = str1.length(); int len2 = str2.length(); if ( len1 != len2 ) return len1-len2; int i=0; while ( i < len2 ) { if ( str1.charAt(i) != str2.charAt(i) ) return (int)str1.charAt(i) - (int)str2.charAt(i); } I guess.... Here I am not sure what would happen on two strings which are not having locale en but still same as the other... Regards Maulin
Well, in compareToIgnoreCase method it is explicitly mentioned that -
Note that this method does not take locale into account, and will result in an unsatisfactory ordering for certain locales. The java.text package provides collators to allow locale-sensitive ordering.
So I was wondering if it is the same with compareTo as well. - manish