集册 Java实例教程 确定ArrayList B是否为ArrayList a的子集

确定ArrayList B是否为ArrayList a的子集

欢马劈雪     最近更新时间:2020-01-02 10:19:05

592
确定ArrayList B是否为ArrayList a的子集
/*来自 nowjava - 时  代  Java*/

//package com.nowjava;

import java.util.ArrayList;


public class Main {

    /**

     * Determines if setB is a subSet of setA

     * 

     * @param setA - the full set for the comparison

     * @param setB - the sub set to be tested 

     * @return true if setB is a subSet of setA 

     * @throws java.lang.IllegalArgumentException - 

     *                  when one of setA or setB is null or empty

     */

    public static boolean subSet(ArrayList<Integer> setA,

            ArrayList<Integer> setB) {

        if (null == setA || null == setB) {

            throw new IllegalArgumentException(

                    "Arralist arguments cannot be null");

        }

        if (setA.size() == 0 || setB.size() == 0) {

            throw new IllegalArgumentException(

                    "Arraylist arguments cannot be empty");

        }


        boolean isInList = true;/*from n o w    j a v a  . c o m*/

        for (int i = 0; i < setA.size() && isInList; i++) {

            is
展开阅读全文