Java String endsWith Example
String class endsWith method example
String class endsWith method example:- This example demonstrates the working of endsWith method. this method examines String last value for matching it to the passed argument as character sequence and generating boolean value on the basis of its relative observation
Syntax:;-endsWith(String suffix)
Here is the code:-
/**
* @(#) EndsWithString.java
* EndsWithString class demonstrates the working of endsWith() method of String class of lang package
* @version 15-May-2008
* @author Rose India Team
*/
public class EndsWithString {
public static void main(String args[]) {
String heram = "Mangalam bhagwan vishnu! Mangalam garurasva ja! Mangalam kundali kakshah! Mangalaya tano hari ";
// method checks whether the defined String ends with passed character
// sequences or word inside parentheses
boolean kayamat = heram.endsWith("kundali");
// method returns false because string mentioned doesnot ends with
// character sequence kundali
System.out.println("false is returned: " + kayamat);
kayamat = heram.endsWith("hari ");
// method here returns true as string ends with word 'hari'
System.out.println("true is returned: " + kayamat);
}
} |
| Java2html |
Output of the program:-
method returns true: true
false is returned: false
|
|