Java String Ends With endsWith(String s, String end)

Here you can find the source of endsWith(String s, String end)

Description

ends With

License

Open Source License

Declaration

public static boolean endsWith(String s, String end) 

Method Source Code

//package com.java2s;
/**//from   w ww .java  2  s  .  co m
 * Copyright (c) 2000-2005 Liferay, LLC. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

public class Main {
    public static boolean endsWith(String s, char end) {
        return startsWith(s, (new Character(end)).toString());
    }

    public static boolean endsWith(String s, String end) {
        if ((s == null) || (end == null)) {
            return false;
        }

        if (end.length() > s.length()) {
            return false;
        }

        String temp = s.substring(s.length() - end.length(), s.length());

        if (temp.equalsIgnoreCase(end)) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean startsWith(String s, char begin) {
        return startsWith(s, (new Character(begin)).toString());
    }

    public static boolean startsWith(String s, String start) {
        if ((s == null) || (start == null)) {
            return false;
        }

        if (start.length() > s.length()) {
            return false;
        }

        String temp = s.substring(0, start.length());

        if (temp.equalsIgnoreCase(start)) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. endsWith(String haystack, String needle)
  2. endsWith(String in, String str)
  3. endsWith(String inEnd, String inValue)
  4. endsWith(String receiver, String... needles)
  5. endsWith(String s, char c)
  6. endsWith(String s, String end)
  7. endsWith(String s, String end)
  8. endsWith(String s, String ending)
  9. endsWith(String s, String suffix)