Page 259 - IT-802_class_12
P. 259
System.out.println(word1 + “ and “ + word2 + “ are equal”);
else
System.out.println(word1 + “ is not same as “ + word2);
Output:
School is not same as SChool
The boolean equalsIgnoreCase(String str) method
Like equals( ) method, this method also checks whether the value of the current string object is the same as the string
str in the parameter. But the difference is that it is not case-sensitive. It returns true if both the strings are equal, even
if they are of different cases, else it returns false. The syntax is:
boolean <variable> = String_datatype_Variable.equalsignoreCase(String str);
Let us see the below example:
String wd1= “india”;
String wd2= “iNDiA”;
boolean eq= wd1.equalsignoreCase(wd2);
if(eq==true)
System.out.println(“The strings “+ wd1 + “ and “ + wd2 + “ are equal “);
else
System.out.println(“The strings “+ wd1 + “ and “ + wd2 + “ are not equal “);
Output:
The strings India and INDIA are equal
The boolean endsWith(String str) method
This method checks whether the string in the current object ends with the string given as a parameter. This function
returns a Boolean-type value. The syntax is:
boolean <variable> = String_datatype_Variable.endsWith(String str);
Let us see the below example:
String sen1= “We are studying in class 12”;
String sen2= “12”;
boolean b=sen1.endsWith(sen2);
if(b)
System.out.println(sen1+ “ ends with “ + sen2);
else
System.out.println(sen1+ “ does not end with “ + sen2);
Output:
We are studying in class 12 ends with 12
The boolean startsWith(String str) method
This function checks whether the string in the current object starts with the string given as parameter. This function
returns a Boolean type value. The syntax is:
boolean <variable> = String_datatype_Variable.startsWith(String str);
Fundamentals of Java Programming 257

