toLanguageTag(): This method is available in java.util.Locale class of Java.
Syntax:
String java.util.Locale.toLanguageTag()
This method returns a well-formed IETF BCP 47 language tag representing this locale.
Note: If this Locale has a language, country, or variant that does not satisfy the IETF BCP 47 language tag syntax requirements, this method handles these fields as described below.
Returns: a BCP47 language tag representing the locale.
For Example:
Locale locale = new Locale("en", "USA", "US")
locale.toLanguageTag()= > It returns en-x-lvariant-US.
Approach
Java
import java.util.Locale;public class LocaletoLanguageTag {public static void main(String[] args) {Locale locale = new Locale("en", "USA", "US");System.out.println(locale.toLanguageTag());}}
Output:
en-x-lvariant-US
No comments:
Post a Comment