String Handling – endsWith ( )

 endsWith ( )

 

Syntax

        boolean endsWith (String str);

endsWith ( ) is standard inbuilt method of String, it is used to compare given string with the last characters of invoking object, if the given string is matched with the last characters of invoking string then it will return true otherwise return false.

class Example

{

public static void main(String arg[ ] )

{

String s1 = “Code project”;

boolean b = s1.endsWith(“project”);

System.out.println(b);

System.out.println(s1.endsWith(“ect”));

System.out.println (s1.endsWith(“sita”));

System.out.println (s1.endsWith(“Code project”));

}

}

output :-

true

true

false

true

Leave a Reply

Your email address will not be published. Required fields are marked *