Here you can find the source of endsWith(List
Parameter | Description |
---|---|
T | the element type |
string | the list |
suffix | the ending elements of the list |
public static <T> boolean endsWith(List<T> string, List<T> suffix)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**/* w ww . ja va 2 s . c o m*/ * Checks if the list ends with specific elements. * * @param <T> the element type * @param string the list * @param suffix the ending elements of the list * @return {@code true} if and only if {@code string} ends with * {@code suffix}, {@code false} otherwise */ public static <T> boolean endsWith(List<T> string, List<T> suffix) { final int stringSize = string.size(); final int suffixSize = suffix.size(); if (suffixSize > stringSize) { return false; } return suffix.equals(string.subList(stringSize - suffixSize, stringSize)); } /** * Check equality in a null-friendly fashion. * * @param a an object * @param b an object to compare with a * @return true if and only if a equals b, false otherwise */ public static boolean equals(Object a, Object b) { return (a == b) || (a != null && a.equals(b)); } }