Java StringCharacterIterator equals()方法及实例

Java StringCharacterIterator equals()方法及实例

Java中 java.text .StringCharacterIterator类equals() 方法用于检查此StringCharacterIterator与指定的StringCharacterIterator是否相等。这个方法接收一个StringCharacterIterator实例,将其与这个StringCharacterIterator进行比较,并返回一个代表相同的布尔值。

语法。

public boolean equals(Object obj)

参数。这个方法接受一个参数 obj ,它是要与这个StringCharacterIterator进行平等检查的StringCharacterIterator。

返回值。该方法返回一个 布尔值 ,告诉你这个StringCharacterIterator是否等于指定的对象。

异常。这个方法不抛出任何异常。

程序。

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程