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 ese false.
Below programs illustrate the working of equals() method:
Program 1:
// 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)); } } |
First Locale: en_US Second Locale: en_US true
Program 2:
// 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)); } } |
First Locale: ar_SA Second Locale: en_GB false
Recommended Posts:
- Locale setDefault(Locale.Category, Locale) Method in Java with Examples
- Locale.Builder setLocale(Locale) method in Java with Examples
- TimeZone getDisplayName(Locale locale) Method in Java with Examples
- Locale getDisplayVariant(Locale inLoc) Method in Java with Examples
- Locale getDisplayCountry(Locale) Method in Java with Examples
- Locale getDisplayLanguage(Locale) Method in Java with Examples
- Locale getDisplayName(Locale) Method in Java with Examples
- Locale getAvailableLocales() Method in Java with Examples
- Locale getISOCountries() Method in Java with Examples
- Locale getCountry() Method in Java with Examples
- Locale getISOLanguages() Method in Java with Examples
- Locale getLanguage() Method in Java with Examples
- Locale getVariant() Method in Java with Examples
- Locale setDefault() Method in Java with Examples
- Scanner locale() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



