Java List Sub List subList(final Iterable

parent, final Iterable child)

Here you can find the source of subList(final Iterable

parent, final Iterable child)

Description

Create sublist view of child from element on [size-of-parent] position to last element.

License

Open Source License

Parameter

Parameter Description
parent a parameter
child a parameter

Exception

Parameter Description
IllegalArgumentException if parent argument is bigger than child

Return

sublist view of child argument

Declaration

private static <P, C> List<C> subList(final Iterable<P> parent, final Iterable<C> child) 

Method Source Code

//package com.java2s;
/*/*www  . j av a  2s. c o m*/
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * Create sublist view of child from element on [size-of-parent] position to
     * last element.
     *
     * @param parent
     * @param child
     * @return sublist view of child argument
     * @throws IllegalArgumentException
     *             if parent argument is bigger than child
     */
    private static <P, C> List<C> subList(final Iterable<P> parent, final Iterable<C> child) {
        Iterator<P> iParent = parent.iterator();
        List<C> result = new ArrayList<>();
        for (C arg : child) {
            if (iParent.hasNext()) {
                iParent.next();
            } else {
                result.add(arg);
            }
        }
        if (iParent.hasNext()) {
            throw new IllegalArgumentException("Parent argument is bigger than child.");
        }
        return result;
    }
}

Related

  1. splitList(List list, int subListNumber)
  2. splitListToSubLists(List parentList, int subListSize)
  3. startsWith(final List list, final List subList)
  4. sub(List l, int index)
  5. subArray(List listA, List listB)
  6. subList(final List oriList, int[] indexes)
  7. subList(final List list, final int first, final int count)
  8. subList(final List list, final int offset, final int amount)
  9. subList(final List list, final int startIndex, final int endIndex)