Here you can find the source of endsWith(CharSequence cs, CharSequence suffix)
Parameter | Description |
---|---|
cs | the first char sequence to test |
suffix | the suffix to test |
public static boolean endsWith(CharSequence cs, CharSequence suffix)
//package com.java2s; public class Main { /** Tests if a char sequence ends with some suffix * @param cs the first char sequence to test * @param suffix the suffix to test * @return true if cs ends with suffix *///from w w w. j av a 2 s .c om public static boolean endsWith(CharSequence cs, CharSequence suffix) { return startsWith(cs, suffix, (cs.length() - suffix.length())); } /** Tests if a char sequence ends with some suffix * @param cs the first char sequence to test * @param suffix the suffix to test * @param caseSensitive do case sensitive comparison? * @return true if cs ends with suffix */ public static boolean endsWith(CharSequence cs, CharSequence suffix, boolean caseSensitive) { return startsWith(cs, suffix, (cs.length() - suffix.length()), caseSensitive); } /** Tests if a char sequence starts with some prefix * @param cs the char sequence to test * @param prefix the prefix to test * @return true if cs starts with prefix */ public static boolean startsWith(CharSequence cs, CharSequence prefix) { return startsWith(cs, prefix, 0, true); } /** Tests if a char sequence starts with some prefix * @param cs the char sequence to test * @param prefix the prefix to test * @param caseSensitive do case sensitive comparison? * @return true if cs starts with prefix */ public static boolean startsWith(CharSequence cs, CharSequence prefix, boolean caseSensitive) { return startsWith(cs, prefix, 0, caseSensitive); } /** Tests if a char sequence starts with some prefix at a specific offset * @param cs the char sequence to test * @param prefix the prefix to test * @param offset the offset to look at * @return true if prefix lies in cs, starting at the specified offset */ public static boolean startsWith(CharSequence cs, CharSequence prefix, int offset) { return startsWith(cs, prefix, offset, true); } /** Tests if a char sequence starts with some prefix at a specific offset * @param cs the char sequence to test * @param prefix the prefix to test * @param offset the offset to look at * @param caseSensitive do case sensitive comparison? * @return true if prefix lies in cs, starting at the specified offset */ public static boolean startsWith(CharSequence cs, CharSequence prefix, int offset, boolean caseSensitive) { if (offset < 0) return false; int prefixLength = prefix.length(); if (cs.length() < (offset + prefixLength)) return false; int c; for (c = 0; (c < prefixLength) && ((c + offset) < cs.length()); c++) if (caseSensitive && cs.charAt(offset + c) != prefix.charAt(c)) return false; else if (!caseSensitive && Character.toLowerCase(cs.charAt(offset + c)) != Character.toLowerCase(prefix.charAt(c))) return false; return (c == prefixLength); } }