String endsWith is used to check if a String ends with the given suffix.
1 |
public boolean endsWith(String suffix) |
endsWith() method returns a boolean value based on the suffix passed
String endsWith example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package com.kscodes.sampleproject; public class StringEndsWithExample { public static void main(String[] args) { String testStr1 = "This is a test String to check endsWith String example"; System.out.println("Does the String ends with 'String' :: "+ testStr1.endsWith("String")); System.out.println("Does the String ends with 'example' :: "+ testStr1.endsWith("example")); System.out.println("--------------------------------------"); System.out.println("Performing a Case Sensitive check"); System.out.println("Does the String ends with 'Example' :: "+ testStr1.endsWith("Example")); } } |
Output
1 2 3 4 5 |
Does the String ends with 'String' :: false Does the String ends with 'example' :: true -------------------------------------- Performing a Case Sensitive check Does the String ends with 'Example' :: false |
Reference
1. String API