java tutorial - Java Strings endsWith () method - java programming - learn java - java basics - java for beginners



 Java - The endsWith() method

Learn java - java tutorial - Java - The endsWith() method - java examples - java programs

Description

Java Strings endsWith () method - checks if this line ends with the specified end.

Syntax

The syntax of the method is:

public boolean endsWith(String suffix)
click below button to copy the code. By - java tutorial - team

Options

  • Detailed information about the parameters:
  • suffix - end.

Return value

  • In Java endsWith (), returns true if the sequence of characters represented by the argument is the end of the sequence of characters represented by this object; otherwise, false.
  • Note that the result is valid if the argument is an empty string or equal to a string object, defined as equals (Object).

Sample Code

public class Test{

   public static void main(String args[]){
      String Str = new String("Welcome to wikitechy.com");
      boolean retVal;

      retVal = Str.endsWith("wikitechy.com");
      System.out.println("Return value: " + retVal);

      retVal = Str.endsWith("wikitechy.com");
      System.out.println("Return value: " + retVal);
   }
}
click below button to copy the code. By - java tutorial - team

Output :

Return value: true
Return value: true

Related Searches to Java Strings endsWith () method