Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> Java

Mastering Java’s String.endsWith(): How to Check String Suffixes with Examples

Java String.endsWith() – Checking a String’s Suffix

The String.endsWith() method determines whether a given string ends with a specified suffix. It returns a boolean: true if the suffix matches the string’s final characters, otherwise false.

Method Signature

public boolean endsWith(String suffix)

Parameter

suffix – The substring to compare against the end of the calling string.

Return Value

Exceptions

Throws NullPointerException if suffix is null.

Practical Example

public class EndsWithDemo {
    public static void main(String[] args) {
        String sample = "Java String endsWith example";
        System.out.println("Ends with 'e':   " + sample.endsWith("e"));   // true
        System.out.println("Ends with 'ple': " + sample.endsWith("ple")); // true
        System.out.println("Ends with 'Java':" + sample.endsWith("Java")); // false
    }
}

Output:

Ends with 'e':   true
Ends with 'ple': true
Ends with 'Java':false

For official documentation, visit String.endsWith().

Java

  1. Encapsulation in Java: A Comprehensive Guide with Practical Example
  2. Master Java String Manipulation: Essential Functions, Methods, and Practical Examples
  3. Java String length() Method: How to Get a String’s Size (Example)
  4. Mastering Java String.indexOf(): Locating Substrings & Practical Examples
  5. Understanding Java String.charAt(): Syntax, Return Type, Exceptions, and a Practical Example
  6. Mastering Java's String compareTo() Method: Syntax, Use Cases, and Practical Examples
  7. Java String.contains() Method: How to Check for Substrings – Practical Examples
  8. Polymorphism in Java: A Comprehensive Guide with Practical Examples
  9. Java Abstraction: Mastering Abstract Classes, Methods, and Practical Examples
  10. Mastering Java's split() Method: A Practical Guide with Code Examples