当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Locale equals()用法及代码示例


Java中的Locale类的equals()方法用于简单地检查两个语言环境对象之间的相等性。如果区域设置对象在从国家到语言以及其他变体的所有方面都相等,则该方法返回true。

用法:

First_Locale.clone(Sec_Locale)

参数:此方法采用一个参数Sec_Locale,它是比较的参考对象。


返回值:如果语言环境与ese匹配,则此方法返回boolean true。

以下示例程序旨在说明equals()方法的用法:

示例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

示例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


相关用法


注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 Locale equals() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。