Forums Register Login

String.compareTo()

+Pie Number of slices to send: Send
Will comparteTo() method of the String class work with internationalization(diff locale)?
- Manish
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
The City calls upon her steadfast protectors. Now for a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 832 times.
Similar Threads
Confusion in Comparable Interface and Comparator Interface examples provided in SCJP6 book
String and internationalization
transform from init() to main()?
lexical search using Pattern and Matcher class
Problem with fmt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:19:35.