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
import java.util.*;
public class Locale_Demo {
public static void main(String[] args)
{
Locale first_locale
= new Locale("en", "US");
Locale sec_locale
= new Locale("en", "US");
System.out.println("First Locale: "
+ first_locale);
System.out.println("Second Locale: "
+ sec_locale);
System.out.println(first_locale
.equals(sec_locale));
}
}
|
Output:
First Locale: en_US
Second Locale: en_US
true
Program 2:
Java
import java.util.*;
public class Locale_Demo {
public static void main(String[] args)
{
Locale first_locale
= new Locale("ar", "SA");
Locale sec_locale
= new Locale("en", "GB");
System.out.println("First Locale: "
+ first_locale);
System.out.println("Second Locale: "
+ sec_locale);
System.out.println(first_locale
.equals(sec_locale));
}
}
|
Output:
First Locale: ar_SA
Second Locale: en_GB
false
Last Updated :
29 Nov, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...