Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the responsive-lightbox domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114
String methods - contentEquals - Testingpool

String methods – contentEquals

ContentEquals() is used to compare the string. It has 2 types of implementations.

  1. boolean contentEquals(CharSequence cs)
  2. boolean contentEquals(StringBuffer sb)

Let’s understand them with the help of examples.

boolean contentEquals(CharSequence cs):

Returns true if string matches with the specified sequence of characters, else returns false.

public class StringMethodsEx {

	public static void main(String[] args) {
		
		String val1 = "Hello world!!";	
		System.out.println(val1.contentEquals("Hello world!!"));  //returns true
		System.out.println(val1.contentEquals("universe"));  //returns false	
	}
}
Output:
true
false

 

boolean contentEquals(StringBuffer sb):

This method compares the String with String buffer. If both matches returns true, else return false.

public class StringMethodsEx {

	public static void main(String[] args) {
		
		String val1 = "Hello world!!";	
               //String buffer
		StringBuffer sf1 = new StringBuffer("Hello world!!");
		StringBuffer sf2 = new StringBuffer("Hello universe!!");
		
		System.out.println(val1.contentEquals(sf1));  //returns true
		System.out.println(val1.contentEquals(sf2));  //returns false	
	}
}
Output:
true
false
Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...