Java List Combine combine(List dest, Collection... src)

Here you can find the source of combine(List dest, Collection... src)

Description

Adds all elements of the src collections to dest, returning dest.

License

Apache License

Declaration

public static <T> List<T> combine(List<T> dest, Collection<T>... src) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.Collection;

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

import java.util.Map;

import java.util.Set;

public class Main {
    /**//from w ww.  ja  va2  s. co  m
     *  Adds all elements of the <code>src</code> collections to <code>dest</code>,
     *  returning <code>dest</code>. This is typically used when you need to combine
     *  collections temporarily for a method argument.
     *
     *  @since 1.0.7
     */
    public static <T> List<T> combine(List<T> dest, Collection<T>... src) {
        for (Collection<T> cc : src) {
            dest.addAll(cc);
        }
        return dest;
    }

    /**
     *  Adds all elements of the <code>src</code> collections to <code>dest</code>,
     *  returning <code>dest</code>. This is typically used when you need to combine
     *  collections temporarily for a method argument.
     *
     *  @since 1.0.7
     */
    public static <T> Set<T> combine(Set<T> dest, Collection<T>... src) {
        for (Collection<T> cc : src) {
            dest.addAll(cc);
        }
        return dest;
    }

    /**
     *  Adds all elements of the <code>src</code> collections to <code>dest</code>,
     *  returning <code>dest</code>. This is typically used when you need to combine
     *  collections temporarily for a method argument.
     *  <p>
     *  Note: source maps are added in order; if the same keys are present in multiple
     *  sources, the last one wins.
     *
     *  @since 1.0.7
     */
    public static <K, V> Map<K, V> combine(Map<K, V> dest, Map<K, V>... src) {
        for (Map<K, V> cc : src) {
            dest.putAll(cc);
        }
        return dest;
    }

    /**
     *  Appends an arbitrary number of explicit elements to an existing collection.
     *  Primarily useful when writing testcases.
     */
    public static <T> void addAll(Collection<T> coll, T... elems) {
        for (T elem : elems)
            coll.add(elem);
    }

    /**
     *  Appends the values returned by an iterator to the passed collection.
     */
    public static <T> void addAll(Collection<T> coll, Iterator<T> src) {
        while (src.hasNext())
            coll.add(src.next());
    }

    /**
     *  Appends the contents of an iterable object to the passed collection.
     */
    public static <T> void addAll(Collection<T> coll, Iterable<T> src) {
        addAll(coll, src.iterator());
    }
}

Related

  1. combine(List> lists)
  2. combine(List commands, int startAt, int endAt)
  3. combine(List strlist, String delimiter)
  4. combine(List tokens, String separator)
  5. combine(List a, List b)
  6. combine(List list, int maxK)
  7. combine(List... dests)
  8. combineAfterIndexWithQuotes(List commands, String match)
  9. combineArray(List> data)