Home » Java programming language

Java Locale getVariant() Method with Example

Locale Class getVariant() method: Here, we are going to learn about the getVariant() method of Locale Class with its syntax and example.
Submitted by Preeti Jain, on March 08, 2020

Locale Class getVariant() method

  • getVariant() method is available in java.util package.
  • getVariant() method is used to get the variant code for this Locale.
  • getVariant() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
  • getVariant() method does not throw an exception at the time of returning variant code.

Syntax:

    public String getVariant();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is String, it returns variant code of this Locale.

Example:

// Java program to demonstrate the example 
// of String getVariant() method of Locale 

import java.util.*;

public class GetVariantOfLocale {
    public static void main(String[] args) {
        // Instantiates Locale
        Locale lo = new Locale("jap", "JAPAN", "AM");

        // Display Locale
        System.out.println("lo: " + lo);

        // By using getVariant() method is
        // to return variant codes
        // for this locale lo
        String
        var = lo.getVariant();
        System.out.println("lo.getVariant(): " +
            var);
    }
}

Output

lo: jap_JAPAN_AM
lo.getVariant(): AM


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.