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

Written by Arpit:

If you have read the post and liked it. Please connect with me on Facebook | Twitter | Google Plus

 

Java tutorial for beginners Copyright © 2012