Here you can find the source of endsWith(final String string, final String[] suffixes)
Parameter | Description |
---|---|
string | The string to check. |
suffixes | The array of suffixes to use. |
public static boolean endsWith(final String string, final String[] suffixes)
//package com.java2s; /*/*w w w . jav a 2s. c o m*/ * Copyright 2011 Eric F. Savage, code@efsavage.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * The Non-breaking space character. */ public static final char NBSP = (char) 160; /** * Checks a string with {@link String#endsWith(String)} against an array of * candidate strings. * * @param string * The string to check. * @param suffixes * The array of suffixes to use. * @return true if the string ends with any of the suffixes, otherwise * false. */ public static boolean endsWith(final String string, final String[] suffixes) { if (isBlank(string) || suffixes == null || suffixes.length == 0) { return false; } for (final String suffix : suffixes) { if (string.endsWith(suffix)) { return true; } } return false; } /** * Looks for null or empty strings. * * @param string * String to be tested, may be null * @return true if string is null or zero-length */ public static boolean isBlank(final String string) { if (string == null) { return true; } if (string.indexOf(NBSP) >= 0) { return isBlank(string.replace(NBSP, ' ')); } return string.length() < 1 || string.trim().length() < 1; } }