Java Data Type Tutorial - Java String .contentEquals ( CharSequence cs)








Syntax

String.contentEquals(CharSequence cs) has the following syntax.

public boolean contentEquals(CharSequence cs)

Example

In the following code shows how to use String.contentEquals(CharSequence cs) method.

public class Main {
// w ww.j  a va 2 s  .c o  m
  public static void main(String[] args) {

    String str1 = "java2s.com", str2 = "Java2s.com";
    CharSequence cs = "java2s.com";
    
    System.out.println("Method returns: " + str1.contentEquals("java2s.com"));
    
    System.out.println("Method returns: " + str1.contentEquals(cs));
  
    System.out.println("Method returns: " + str2.contentEquals("12345"));
  }
}

The code above generates the following result.