Page 307 - ComputerScience_Class_11
P. 307
3 {
4 String sen1= "Welcome to our school";
5 String sen2= "WELCOME to our school";
6 int value= sen1.compareToIgnoreCase(sen2);
7 System.out.println("Value: "+ value);
8 }
9 }
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
Value: 0
The endsWith(String str) Function
This function 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:
Program 20 Write a program to check if a string ends with a specified suffix and print the result.
1 class endswith
2 {
3 public static void main(String[] args)
4 {
5 String sen1= "We are studying in class 11";
6 String sen2= "11";
7 boolean b=sen1.endsWith(sen2);
8 if(b)
9 System.out.println(sen1+ " ends with " + sen2);
10 else
11 System.out.println(sen1+ " does not end with " + sen2);
12 }
13 }
Strings 305

