Java List Ends with endsWith(List string, List suffix)

Here you can find the source of endsWith(List string, List suffix)

Description

Checks if the list ends with specific elements.

License

Open Source License

Parameter

Parameter Description
T the element type
string the list
suffix the ending elements of the list

Return

true if and only if string ends with suffix , false otherwise

Declaration

public static <T> boolean endsWith(List<T> string, List<T> suffix) 

Method Source Code

//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));
    }
}

Related

  1. endsWith(List left, List right, boolean equals)
  2. endsWith(List left, List right, boolean equals)
  3. endsWith(List source, List prefix)
  4. endsWith(List hierarchy, String... items)
  5. endsWith(List lst, List suffix)