Java Data Type Tutorial - Java String .contentEquals ( StringBuffer sb)








Syntax

String.contentEquals(StringBuffer sb) has the following syntax.

public boolean contentEquals(StringBuffer sb)

Example

In the following code shows how to use String.contentEquals(StringBuffer sb) method.

public class Main {
/*from  ww  w .j  av a2  s . c  om*/
  public static void main(String[] args) {
 
    String str1 = "java2s.com";
    String str2 = "java2s.com";
    
    StringBuffer strbuf = new StringBuffer(str1);
    System.out.println("Method returns : " + str2.contentEquals(strbuf));
  
    str2 = str1.toUpperCase();
    System.out.println("Method returns : " + str2.contentEquals(strbuf));
  }
}

The code above generates the following result.