Java String endsWith() method example.


The endsWith() method of the class String accepts another string representing the suffix, tests weather the current string ends with the given suffix. If so, it returns true else it returns false.

Example

 Live Demo

public class Test {
   public static void main(String args[]) {
      String Str = new String("This is really not immutable!!");
      boolean retVal;
      retVal = Str.endsWith( "immutable!!" );
      System.out.println("Returned Value = " + retVal );
      retVal = Str.endsWith( "immu" );
      System.out.println("Returned Value = " + retVal );
   }
}

Output

Returned Value = true
Returned Value = false

Updated on: 30-Jul-2019

145 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements