Here you can find the source of endsWith(CharSequence source, CharSequence search)
public static boolean endsWith(CharSequence source, CharSequence search)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { /**//from www . ja v a 2s.c o m * Returns true if the source sequence ends with the search sequence. This is a * call to {@link #containsAt} with calculated location. */ public static boolean endsWith(CharSequence source, CharSequence search) { if (source == null) return false; if (search == null) return false; int loc = source.length() - search.length(); return containsAt(source, search, loc); } /** * Returns true of the passed source sequence contains the specified search * sequence starting at the given location. Will return false if either the * source or search sequences are null, or the specified location is outside * of the source sequence (either high or low). */ public static boolean containsAt(CharSequence source, CharSequence search, int loc) { if (source == null) return false; if (search == null) return false; if (loc < 0) return false; if (loc + search.length() > source.length()) return false; for (int ii = 0; ii < search.length(); ii++) { if (source.charAt(loc + ii) != search.charAt(ii)) return false; } return true; } }