A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://howtodoinjava.com/java/string/java-string-endswith-method/ below:

Java String endsWith() with Examples

Java String.endsWith() is used to check the suffix of a given string. It verifies if the given string ends with the argument string or not. To check if a string starts with a specified substring, use startsWith() method.

Note that using the regular expression is also an effective way to check if the given string ends with the specified pattern.

1. String.endsWith() API

The endsWith() method takes one string argument and checks if the argument string is present at the end of this string.

public boolean endsWith(String suffix);

The method returns a boolean value indicating:

2. Regular Expressions are Not Supported

String endsWith() does not accept the regular expression as the method argument. If we pass the regex pattern as the argument, it will only be treated as a normal string.

Assertions.assertFalse( name.endsWith("java$") );
3. NULL is Not Allowed

The null is not allowed as a method argument, and any such attempt will throw NullPointerException.

Assertions.assertThrows(NullPointerException.class, ()->{
    name.endsWith(null);
});

Reference: Java String Doc


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4