How does the compiler compares the strings ?
Like :
print ( “bahaa” > “bahaa” )
I know how does the compiler compares the characters using Unicode but what about the strings.
How does the compiler compares the strings ?
Like :
print ( “bahaa” > “bahaa” )
I know how does the compiler compares the characters using Unicode but what about the strings.
I can’t say for absolute sure (someone else might chime in), but I suspect it comes down to the Java compareTo method under the hood…
Java characters are UTF-16 under the hood. I’m not sure, but I think the compare function is NLS dependent. You need to use a collator to ensure a constant result.
https://docs.oracle.com/javase/tutorial/i18n/text/locale.html
That’s correct.
So to be totally clear, there is an implicit conversion in the standard library which adds a bunch of extension methods to String
. "bahaa" > "bahaa"
actually desugars to
scala.Predef.augmentString("bahaa").>("bahaa")