📜  Java中的 ChoiceFormat equals() 方法及示例

📅  最后修改于: 2022-05-13 01:54:53.934000             🧑  作者: Mango

Java中的 ChoiceFormat equals() 方法及示例

Java.text.ChoiceFormat类的equals()方法用于在两个ChoiceFormat 对象之间进行比较,并给出比较的布尔值。
句法:

public boolean equals(Object obj)

参数:此方法以obj作为参数,这是另一个用于比较的 ChoiceFormat 对象。
返回值:如果两个选择格式对象相等,则此方法返回true ,否则返回 false。
以下是说明equals()方法的示例:
示例 1:

Java
// 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");
    }
}


Java
// 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 equal

示例 2:

Java

// 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-