java.text.ParsePosition類的equals()方法用於檢查兩個ParsePosition對象是否相同。
用法:
public boolean equals(Object obj)
參數:此方法采用ParsePosition對象,該對象將與當前ParsePosition對象進行比較。
返回值:如果兩個ParsePosition對象彼此相等,則它將返回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 ParsePosition Object
ParsePosition pos_1
= new ParsePosition(0);
// Creating and initializing
// new ParsePosition Object
ParsePosition pos_2
= new ParsePosition(0);
// 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(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 ParsePosition Object
ParsePosition pos_1
= new ParsePosition(0);
// Creating and initializing
// new ParsePosition Object
ParsePosition pos_2
= new ParsePosition(1);
// 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(e);
}
}
}
輸出:
pos_1 is not equal to pos_2
參考: https://docs.oracle.com/javase/9/docs/api/java/text/ParsePosition.html#equals-java.lang.Object-
相關用法
- Java ParsePosition setIndex()用法及代碼示例
- Java ParsePosition getIndex()用法及代碼示例
- Java ParsePosition toString()用法及代碼示例
- Java ParsePosition hashCode()用法及代碼示例
- Java ParsePosition setErrorIndex()用法及代碼示例
- Java ParsePosition getErrorIndex()用法及代碼示例
- Java DateFormat parse(string , ParsePosition)用法及代碼示例
- Java MessageFormat equals()用法及代碼示例
- Java Map equals()用法及代碼示例
- Java AbstractSequentialList equals()用法及代碼示例
- Java LongBuffer equals()用法及代碼示例
- Java DecimalFormat equals()用法及代碼示例
- Java YearMonth equals()用法及代碼示例
- Java CopyOnWriteArraySet equals()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 ParsePosition equals() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。