Here you can find the source of endsWith(CharSequence s, CharSequence sub)
Parameter | Description |
---|---|
s | The search space. |
sub | The substring to evaluate. |
public static boolean endsWith(CharSequence s, CharSequence sub)
//package com.java2s; /*//w ww. j a v a 2s . c o m Copyright (c) 1996-2013 Ariba, Inc. All rights reserved. Patents pending. 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. $Id: //ariba/platform/util/core/ariba/util/core/StringUtil.java#41 $ */ public class Main { /** * Evaluates if the first CharSequence ends with the second. If both * strings are null, then the substring is considered to be a substring * of the search string. * @param s The search space. * @param sub The substring to evaluate. * @return True when s ends with sub or both values are null. */ public static boolean endsWith(CharSequence s, CharSequence sub) { // special-case nulls, (null, null) should be true if (null == s) { return null == sub; } else if (null == sub) { return false; } int l1 = s.length(); int l2 = sub.length(); // .toString required, because .equals on CharSequence doesn't // behave as expected return l1 >= l2 && s.subSequence(l1 - l2, l1).equals(sub.toString()); } }