java.text.FieldPosition類的equals()方法用於檢查兩個FieldPosition對象是否相同。
用法:
public boolean equals(Object obj)
參數:此方法采用FieldPosition對象,該對象將與當前FieldPosition對象進行比較。
返回值:如果兩個FieldPosition對象彼此相等,則它將返回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)
{
try {
// Creating and initializing
// new FieldPosition Object
FieldPosition pos_1
= new FieldPosition(
DateFormat.Field.AM_PM);
// Creating and initializing
// new FieldPosition Object
FieldPosition pos_2
= new FieldPosition(
DateFormat.Field.AM_PM);
// compare both object
// using equals() mehtod
boolean i = pos_1.equals(pos_2);
// display result
if (i)
System.out.println(
"pos_1 is equals to pos_2");
else
System.out.println(
"pos_1 is not equal to pos_2");
}
catch (ClassCastException e) {
System.out.println("Exception thrown:" + e);
}
}
}
輸出:
pos_1 is equals to pos_2
範例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)
{
try {
// Creating and initializing
// new FieldPosition Object
FieldPosition pos_1
= new FieldPosition(
DateFormat.Field.AM_PM);
// Creating and initializing
// new FieldPosition Object
FieldPosition pos_2
= new FieldPosition(
MessageFormat.Field.ARGUMENT);
// compare both object
// using equals() mehtod
boolean i = pos_1.equals(pos_2);
// display result
if (i)
System.out.println(
"pos_1 is equals to pos_2");
else
System.out.println(
"pos_1 is not equal to pos_2");
}
catch (ClassCastException e) {
System.out.println("Exception thrown:" + e);
}
}
}
輸出:
pos_1 is not equal to pos_2
參考: https://docs.oracle.com/javase/9/docs/api/java/text/FieldPosition.html#equals-java.lang.Object-
相關用法
- Java FieldPosition setEndIndex()用法及代碼示例
- Java FieldPosition getBeginIndex()用法及代碼示例
- Java FieldPosition getField()用法及代碼示例
- Java FieldPosition hashCode()用法及代碼示例
- Java FieldPosition toString()用法及代碼示例
- Java FieldPosition getFieldAttribute()用法及代碼示例
- Java FieldPosition setBeginIndex()用法及代碼示例
- Java FieldPosition getEndIndex()用法及代碼示例
- Java HashSet equals()用法及代碼示例
- Java MessageFormat equals()用法及代碼示例
- Java MathContext equals()用法及代碼示例
- Java IdentityHashMap equals()用法及代碼示例
- Java IntBuffer equals()用法及代碼示例
- Java CharBuffer equals()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 FieldPosition equals() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。