Java Locale区分大小写 [英] Java Locale case sensitivity

查看:93
本文介绍了Java Locale区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码来显示当前区域设置

I have the following code to display current locale

System.out.println(Locale.getDefault());
System.out.println(new Locale("en_US"));

上面给出的输出如下

en_US
en_us

如何构建区域设置提供 en_US 的实例?

How do I construct a Locale instance which gives en_US ?

编辑

我问这个是因为我的资源是 Messages_en_US.properties 当我尝试将其设置为默认语言环境时,如果在

I am asking this because my resources which is Messages_en_US.properties is being ignored when I try to set it as default locale if any exception occurs during

ResourceBundle.getBundle("Messages", new Locale("en_US"));


推荐答案

new Locale("en_US")

是一个语言代码为en_us的语言环境

new Locale("en", "US")

是一种语言环境,其语言代码为en,其国家代码是US

is a locale whose language code is "en", and whose country code is "US".

javadoc 说单参数构造函数:


区域设置



Locale

public Locale(String language)

从语言代码构造语言环境。此构造函数将语言值规范化为小写。

Construct a locale from a language code. This constructor normalizes the language value to lowercase.

这篇关于Java Locale区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆