Java中的 StringCharacterIterator equals() 方法及示例
Java中Java .text.StringCharacterIterator 类的equals()方法用于检查此StringCharacterIterator 与指定的StringCharacterIterator 是否相等。此方法采用 StringCharacterIterator 实例并将其与此 StringCharacterIterator 进行比较,并返回一个表示相同的布尔值。
句法:
public boolean equals(Object obj)
参数:此方法接受参数obj ,它是要检查与此 StringCharacterIterator 是否相等的 StringCharacterIterator。
返回值:此方法返回一个布尔值,用于判断此 StringCharacterIterator 是否等于指定的 Object。
异常:此方法不抛出任何异常。
程序:
// Java program to demonstrate
// the above method
import java.text.*;
import java.util.*;
public class StringCharacterIteratorDemo {
public static void main(String[] args)
{
StringCharacterIterator sci1
= new StringCharacterIterator(
"GeeksforGeeks");
System.out.println("StringCharacterIterator 1: "
+ sci1);
StringCharacterIterator sci2
= new StringCharacterIterator(
"Geeks for Geeks");
System.out.println("StringCharacterIterator 2: "
+ sci2);
StringCharacterIterator sci3
= (StringCharacterIterator)sci1
.clone();
System.out.println("StringCharacterIterator 3: "
+ sci3);
System.out.println("Comparing DFS 1 and DFS 2: "
+ sci1.equals(sci2));
System.out.println("Comparing DFS 2 and DFS 3: "
+ sci2.equals(sci3));
System.out.println("Comparing DFS 1 and DFS 3: "
+ sci1.equals(sci3));
}
}
输出:
StringCharacterIterator 1: java.text.StringCharacterIterator@bd43b778
StringCharacterIterator 2: java.text.StringCharacterIterator@ac5740a8
StringCharacterIterator 3: java.text.StringCharacterIterator@bd43b778
Comparing DFS 1 and DFS 2: false
Comparing DFS 2 and DFS 3: false
Comparing DFS 1 and DFS 3: true
参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/StringCharacterIterator.html#equals-java.lang.Object-