![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Importance of a Locale class in Java?
A Locale class is used to perform locale operations and supply locale information to the user. A Locale is defined as a set of parameters that represents a geographical location or place where some operation occurs. The important methods of Locale class are getAvailableLocales(), getCountry(), getDefault(), getDisplayLanguage(), getDisplayCountry(), getUnicodeLocaleKeys() etc.
The Locale class uses the following constructors −
Locale(String L)− Initializes locale from the language code passed as an argument.
Locale(String L, String C) − Initializes locale from the language, country code passed as arguments.
Locale(String L, String C, String V) − Initializes locale from the language, country, variant passed as arguments.
Example
import java.text.SimpleDateFormat; import java.util.Locale; public class LocaleTest { public static void main(String[] args) { Locale loc[] = SimpleDateFormat.getAvailableLocales(); for (int i=1; i <= 15; i++) { System.out.printf("%s (%s) \n", loc[i].getDisplayName(), loc[i].toString()); } } }
Output
Norwegian Nynorsk (nn) Arabic (Jordan) (ar_JO) Bulgarian (bg) Kabuverdianu (kea) Low German (nds) Zulu (zu) Amharic (Ethiopia) (am_ET) French (Algeria) (fr_DZ) Tigrinya (Ethiopia) (ti_ET) Tibetan (China) (bo_CN) Upper Sorbian (hsb) Quechua (Ecuador) (qu_EC) Tamil (Singapore) (ta_SG) Latvian (lv) English (Niue) (en_NU)
Advertisements