Java String.contentEquals() Method Example

The String.contentEquals()

There are two versions of contentEquals methods;
  1. contentEquals(CharSequence cs)  - Compares this string to the specified  CharSequence.
  2. contentEquals(StringBuffer sb)  - Compares this string to the specified  StringBuffer.

Java String.contentEquals() Method Example

public class ContentEqualsExample {
    public static void main(String[] args) {
        String str = "javaguides";
        String subStr = "javaguides";
        boolean isContentEquals = str.contentEquals(subStr);
        System.out.println("isContentEquals :: " + isContentEquals);
        isContentEquals = str.contentEquals(new StringBuffer(subStr));
        System.out.println("isContentEquals :: " + isContentEquals);
    }
}

Output:
isContentEquals:: true isContentEquals:: true 

Reference

Comments