Java.util.Locale.toString() Method


Advertisements


Description

The java.util.Locale.toString() method is a getter for the programmatic name of the entire locale, with the language, country and variant separated by underbars

Declaration

Following is the declaration for java.util.Locale.toString() method

public final String toString()

Parameters

  • NA

Return Value

This method returns a string representation of the object.

Exception

  • NA

Example

The following example shows the usage of java.util.Locale.toString() method.

package com.tutorialspoint;

import java.util.*;

public class LocaleDemo {

   public static void main(String[] args) {

   // create a new locale
   Locale locale1 = new Locale("en", "US", "WIN");

   // print locale
   System.out.println("Locale:" + locale1);

   // print the locale as a string
   System.out.println("Locale:" + locale1.toString());

   // create a new locale
   Locale locale2 = new Locale("fr", "FRANCE", "WIN");

   // print locale
   System.out.println("Locale2:" + locale2);

   // print the locale as a string
   System.out.println("Locale2:" + locale2.toString());

   }
}

Let us compile and run the above program, this will produce the following result:

Locale:en_US_WIN
Locale:en_US_WIN
Locale2:fr_FRANCE_WIN
Locale2:fr_FRANCE_WIN

java_util_locale.htm

Advertisements