當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java ChoiceFormat equals()用法及代碼示例


java.text.ChoiceFormat類的equals()方法用於在兩個ChoiceFormat對象之間進行比較,並提供有關比較的布爾值。

用法:

public boolean equals(Object obj)

參數:此方法將obj作為參數,這是另一個ChoiceFormat對象用於比較。


返回值:如果兩個選擇格式對象都相等,則此方法返回true,否則返回false。

下麵是說明equals()方法的示例:

示例1:

// Java program to demonstrate equals() method 
  
import java.text.*; 
import java.util.*; 
import java.io.*; 
  
public class GFG { 
    public static void main(String[] argv) 
    { 
        // creating and initializing ChoiceFormat 
        ChoiceFormat cf1 
            = new ChoiceFormat( 
                "4#wed| 5#thu | 6#fri | 7#sat"); 
  
        // creating and initializing ChoiceFormat 
        ChoiceFormat cf2 
            = new ChoiceFormat( 
                "4#wed| 5#thu | 6#fri | 7#sat"); 
  
        // compare cf1 and cf2 
        // using equals() method 
        boolean status = cf1.equals(cf2); 
  
        // display the result 
        if (status) 
            System.out.println("Both ChoiceFormat"
                               + " objects are equal"); 
        else
            System.out.println("Both ChoiceFormat "
                               + "objects are not equal"); 
    } 
}
輸出:
Both ChoiceFormat objects are equal

示例2:

// Java program to demonstrate equals() method 
  
import java.text.*; 
import java.util.*; 
import java.io.*; 
  
public class GFG { 
    public static void main(String[] argv) 
    { 
        // creating and initializing ChoiceFormat 
        ChoiceFormat cf1 
            = new ChoiceFormat( 
                "1#sun| 2#mon | 3#tues | 4#wed"); 
  
        // creating and initializing ChoiceFormat 
        ChoiceFormat cf2 
            = new ChoiceFormat( 
                "4#wed| 5#thu | 6#fri | 7#sat"); 
  
        // compare cf1 and cf2 
        // using equals() method 
        boolean status = cf1.equals(cf2); 
  
        // display the result 
        if (status) 
            System.out.println("Both ChoiceFormat"
                               + " objects are equal"); 
        else
            System.out.println("Both ChoiceFormat "
                               + "objects are not equal"); 
    } 
}
輸出:
Both ChoiceFormat objects are not equal

參考: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#applyPattern-java.lang.String-



相關用法


注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 ChoiceFormat equals() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。