Java API Tutorial - Java Locale.equals(Object obj)








Syntax

Locale.equals(Object obj) has the following syntax.

public boolean equals(Object obj)

Example

In the following code shows how to use Locale.equals(Object obj) method.

/*from   w  w w.  j a va  2 s  .c om*/

import java.util.Locale;

public class Main {

   public static void main(String[] args) {
      Locale locale1 = new Locale("ENGLISH", "US");

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

      // create a second locale
      Locale locale2 = new Locale("GERMANY", "GERMAN");

      // compare two locales
      System.out.println("Locales are equal:" + locale1.equals(locale2));

      // create a third locale
      Locale locale3 = new Locale("ENGLISH", "US");

      // compare locale1 and locale3
      System.out.println("Locales are equal:" + locale1.equals(locale3));
   }
}

The code above generates the following result.