Locale equals() Method in Java with Examples
The equals() Method of Locale class in Java is used to simply check the equality between two locale objects. The method returns true if the locale objects are equal at all aspects from country to language and other variants. Syntax:
First_Locale.clone(Sec_Locale)
Parameters: This method takes one parameter Sec_Locale which is the reference object for the comparison. Return Value: This method returns boolean true if the locale matches false. Below programs illustrate the working of equals() method: Program 1:
Java
// Java code to illustrate equals() method import java.util.*; public class Locale_Demo { public static void main(String[] args) { // Creating a new locale Locale first_locale = new Locale("en", "US"); Locale sec_locale = new Locale("en", "US"); // Displaying first locale System.out.println("First Locale: " + first_locale); // Displaying second locale System.out.println("Second Locale: " + sec_locale); // Displaying the equality System.out.println(first_locale .equals(sec_locale)); } } |
Output:
First Locale: en_US Second Locale: en_US true
Program 2:
Java
// Java code to illustrate equals() method import java.util.*; public class Locale_Demo { public static void main(String[] args) { // Creating a new locale Locale first_locale = new Locale("ar", "SA"); Locale sec_locale = new Locale("en", "GB"); // Displaying first locale System.out.println("First Locale: " + first_locale); // Displaying second locale System.out.println("Second Locale: " + sec_locale); // Displaying the equality System.out.println(first_locale .equals(sec_locale)); } } |
Output:
First Locale: ar_SA Second Locale: en_GB false