Java Utililty Methods String Ends With

List of utility methods to do String Ends With

Description

The list of methods to do String Ends With are organized into topic(s).

Method

booleanendsWithLineSeparator(final CharSequence msg)
ends With Line Separator
final int len = msg.length();
final String ls = LINE_SEPARATOR;
if (ls != null && len > ls.length()) {
    final int end = len - ls.length();
    return ls.equals(msg.subSequence(end, len));
return false;
booleanendsWithName(String subject, String endName)
ends With Name
if (!subject.endsWith(endName)) {
    return false;
if (endName.length() == 0) {
    return true;
final int deltaLength = subject.length() - endName.length();
if (deltaLength == 0) {
...
booleanendsWithNewline(String string)
ends With Newline
if (string.isEmpty()) {
    return false;
final char character = string.charAt(string.length() - 1);
return character == '\r' || character == '\n';
intendsWithOne(final String src, final String[] dest)
ends With One
for (int i = 0; i < dest.length; ++i) {
    final String m = dest[i];
    if (m != null) {
        if (src.endsWith(m)) {
            return i;
return -1;
intendsWithOne(String src, String... dest)
ends With One
for (int i = 0; i < dest.length; i++) {
    String m = dest[i];
    if (m != null) {
        if (src.endsWith(m))
            return i;
return -1;
...
booleanendsWithOneOf(String value, String... ends)
Test if the String value ends with one of the specified ends.
for (String end : ends) {
    if (value.endsWith(end)) {
        return true;
return false;
StringendsWithoutPathSeparator(final String path)
Make sure a given path does not end with a path separator character.
String returnedPath;
if (path.endsWith("/") || path.endsWith("\\")) {
    returnedPath = path.substring(0, path.length() - 1);
} else {
    returnedPath = path;
return returnedPath;
StringendsWithoutSlash(String url)
ends Without Slash
return url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
booleanendsWithSentenceSeparator(char[] token)
Check if token ends with a sentence separator
return token.length > 2 && isSentenceSeparator(token[token.length - 1]);
booleanendsWithSeparator(String str)
ends With Separator
return str != null && (str.endsWith("/") || str.endsWith("\\"));