Java String contentEquals example

String’s contentEquals method is used to compare String with StringBuffer. It returns boolean datatype.

Method syntax:

public boolean contentEquals(StringBuffer sb)

String contentEquals Example:

package org.arpit.java2blog;

public class StringContentEqualsExample {
 public static void main(String[] args) {
  String str1 = "java2blog";
  String str2="Hello world from java2blog";
  String str3="JAVA2BLOG";

  StringBuffer sb=new StringBuffer("java2blog");

  System.out.println(str1.contentEquals(sb));
  System.out.println(str2.contentEquals(sb));
  System.out.println(str3.contentEquals(sb));

 }
}

When you run above program, you will get below output:

true
false
false

Please note that contentEquals method is case sensitive as you can see in above example

[social_share share_on="facebook,twitter,linkedin,whatsapp"][post_navigator in_same_term="true"]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.