Here you can find the source of startsWith(List
Parameter | Description |
---|---|
T | the element type |
string | the list |
prefix | the starting elements of the list |
public static <T> boolean startsWith(List<T> string, List<T> prefix)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**//from w ww .ja v a2 s . c o m * Checks if the list starts with specific elements. * * @param <T> the element type * @param string the list * @param prefix the starting elements of the list * @return {@code true} if and only if {@code string} starts with * {@code prefix}, {@code false} otherwise */ public static <T> boolean startsWith(List<T> string, List<T> prefix) { final int stringSize = string.size(); final int prefixSize = prefix.size(); if (prefixSize > stringSize) { return false; } return prefix.equals(string.subList(0, prefixSize)); } /** * 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)); } }