Here you can find the source of endsWith(String a, char[] b)
String.endsWith(String)
using a char[]
.
Parameter | Description |
---|---|
a | String to test. |
b | suffix to test. |
true
if a
ends with b
.
public static boolean endsWith(String a, char[] b)
//package com.java2s; /*//from w ww . ja v a 2 s . co m * This file is part of muCommander, http://www.mucommander.com * Copyright (C) 2002-2010 Maxence Bernard * * muCommander is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * muCommander is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Equivalent of <code>String.endsWith(String)</code> using a <code>char[]</code>. * @param a String to test. * @param b suffix to test. * @return <code>true</code> if <code>a</code> ends with <code>b</code>. */ public static boolean endsWith(String a, char[] b) { return matches(a, b, a.length()); } /** * Returns <code>true</code> if the substring of <code>a</code> starting at <code>posA</code> matches <code>b</code>. * @param a String to test. * @param b substring to look for. * @param posA position in <code>a</code> at which to look for <code>b</code> * @return <code>true</code> if <code>a</code> contains <code>b</code> at position <code>posA</code>, <code>false</code> otherwise.. */ public static boolean matches(String a, char[] b, int posA) { int posB; if (posA < (posB = b.length)) return false; while (posB > 0) if (a.charAt(--posA) != b[--posB]) return false; return true; } }