Why does java.util.Locale.US
show en_US
? When we construct, why do we need to pass it as en-US
?
What is the difference between these?
Why does java.util.Locale.US
show en_US
? When we construct, why do we need to pass it as en-US
?
What is the difference between these?
You see both versions quite often. However, RFC 5646 (which is part of the IETF BCP 47 document series) prescribes a hyphen as the separator character. Java seems to allow both versions:
Well-formed variant values have the form
SUBTAG (('_'|'-') SUBTAG)*
whereSUBTAG = [0-9][0-9a-zA-Z]{3} | [0-9a-zA-Z]{5,8}
. (Note: BCP 47 only uses hyphen ('-') as a delimiter, this is more lenient).