How to get Locale from its String representation in Java?

前端 未结 12 1047
慢半拍i
慢半拍i 2020-12-08 00:06

Is there a neat way of getting a Locale instance from its \"programmatic name\" as returned by Locale\'s toString() method? An obvious and ugly solution would b

12条回答
  •  旧巷少年郎
    2020-12-08 00:27

    If you are using Spring framework in your project you can also use:

    org.springframework.util.StringUtils.parseLocaleString("en_US");
    

    Documentation:

    Parse the given String representation into a Locale

提交回复
热议问题