String endsWith(String suffix) method in Java

The boolean endsWith(String suffix) method in Java tests if this string ends with the specified suffix.

Syntax

Let us see the syntax,

boolean endsWith(String suffix)

Parameters

Let us see the parameters,

  • suffix – string for suffix

Example

The following is an example of endsWith(String suffix),

public class StudyopediaDemo {

   public static void main(String args[]) {
	 
     boolean result;
     String message = new String("Welcome to Studyopedia");

     result = message.endsWith( "Study" );
     System.out.println("Result: " + result );

     result = message.endsWith( "Studyopedia" );
     System.out.println("Result: " + result );
	 
     result = message.endsWith( "pedia" );
     System.out.println("Result: " + result );
  } 
}

Output

The following is the output,

Java String endswith method

String copyValueOf(char[] data, int offset, int count) method in Java
String equals(Object anObject) method in Java
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment