Java String contentEquals Example
String class ContentEqual method example
String class ContentEqual method example:- This example demonstrates the working of contentEquals method. this method checks whole String and CharSequence value and then generates boolean values.
Here is the code:-
/**
* @(#) ContentEqualsString.java
* ContentEqualsString class demonstrates the working of contentEquals() method of String class of lang package
* @version 14-May-2008
* @author Rose India Team
*/
public class ContentEqualsString {
public static void main(String args[]){
//method shows that it returns true for two java elements that cantain same values and none of them contain anything extra data
//method compare complete String value to complete CharSequence value and declare its result
// method contentEqual() compares the String value directly to the
// CharsSequence value and generates boolean type result
CharSequence scenario = "baadshah khan is my name", scenario1;
String str = "baadshah khan is my name", str1 = "420";
System.out.println("");
//one process in two different ways and finally generating same results"
System.out.println("Method returns 'true' in both cases: " + str.contentEquals("baadshah khan is my name") + " --- " + str.contentEquals(scenario));
System.out.println("");
//Method here returns 'false' because String str1 did not match completely to CharSequence variable scenario's value"
System.out.println("'false' is returned here: " + str1.contentEquals("420_9211"));
String heram = new String(" jai_maha_kaal"), prabhu = heram.toUpperCase();
StringBuffer baadshah = new StringBuffer(heram);
System.out.println("");
// String prabhu and StringBuffer do not posses same value as their value differ in cases"
System.out.println("Method returns 'false' here: " + prabhu.contentEquals(baadshah));
}
}
|
Output of the program:-
Method returns 'true' in both cases: true --- true
'false' is returned here: false
Method returns 'false' here: false
|
|