Here you can find the source of subArray(List
Parameter | Description |
---|---|
T | the generic type |
listA | the list a |
listB | the list b |
public static <T> boolean subArray(List<T> listA, List<T> listB)
//package com.java2s; /*/*w ww.ja v a 2 s. c om*/ Copyright 2014 Array-Utilities Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. * */ import java.util.Collection; import java.util.List; public class Main { /** * Sub array. * * @param <T> * the generic type * @param listA * the list a * @param listB * the list b * @return true, if successful * * Case Insensitive */ public static <T> boolean subArray(List<T> listA, List<T> listB) { // ListA empty & ListB has values if (isEmpty(listA) && !isEmpty(listB)) { return false; } // ListA has values & ListB is empty if (!isEmpty(listA) && isEmpty(listB)) { return false; } if (isSizeZero(listA) && isSizeZero(listB)) { return true; } if (isListNull(listA) && isListNull(listB)) { return true; } return listA.containsAll(listB); } /** * Checks if is empty. * * @param <E> * the element type * @param collection * the collection * @return true, if is empty */ public static <E> boolean isEmpty(Collection<? super E> collection) { if ((collection.size() == 0) || (collection == null)) return true; return false; } /** * Checks if is size zero. * * @param <T> * the generic type * @param list * the list * @return true, if is size zero */ public static <T> boolean isSizeZero(List<T> list) { return list.size() == 0; } /** * Checks if is list null. * * @param <T> * the generic type * @param list * the list * @return true, if is list null */ public static <T> boolean isListNull(List<T> list) { return list == null; } }
parent, final Iterable