當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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-



相關用法


注:本文由純淨天空篩選整理自ShubhamMaurya3大神的英文原創作品 StringCharacterIterator equals() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。