Java String endsWith() method example.

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 12-Feb-2018 10:16:23
Advertisements