- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java Locale getExtension() Method
Description
The Java Locale getExtension(char key) method returns the extension (or private use) value associated with the specified key, or null if there is no extension associated with the key. To be well-formed, the key must be one of [0-9A-Za-z]. Keys are case-insensitive, so for example 'z' and 'Z' represent the same extension.
Declaration
Following is the declaration for java.util.Locale.getExtension(char key) method
public String getExtension(char key)
Parameters
key − the extension key
Return Value
This method returns the extension, or null if this locale defines no extension for the specified key.
Exception
IllegalArgumentException − if key is not well-formed.
Getting Extension from a Locale Example
The following example shows the usage of Java Locale getExtension() method. We're creating a locale using Builder with a given extension with a key. Then using getExtension() method, extension is printed for an existing key and then it is printed for non-existent key.
package com.tutorialspoint; import java.util.Locale; import java.util.Locale.Builder; public class LocaleDemo { public static void main(String[] args) { // create a new locale Locale locale = new Builder().setExtension('a', "sample-ex-tension").build(); // print the extension for 'a' System.out.println("Extension:" + locale.getExtension('a')); // print the extension for 'b' as null System.out.println("Extension:" + locale.getExtension('b')); } }
Output
Let us compile and run the above program, this will produce the following result −
Extension:sample-ex-tension Extension:null
To Continue Learning Please Login
Login with Google