集册 Java实例教程 提供给定集合的浅表副本。

提供给定集合的浅表副本。

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

367
提供给定集合的浅副本。
// 来自 时 代 J     a    v  a - nowjava.com

//package com.nowjava;

import java.util.ArrayList;

import java.util.Collection;


import java.util.List;


public class Main {

    /**

     * Provides a shallow copy of the given collection.

     * Removes all <code>null</code> items from <code>srcList</code>,

     *

     * @param srcList The source list. May be <code>null</code> and may contain <code>null</code> items.

     * @return A list with no <code>null</code> items. Never <code>null</code>.

     */

    public static <T> List<T> shallowCopyWithoutNulls(Collection<T> srcList) {

        if (srcList == null) {

            return new ArrayList<T>();

        }


        List<T> copy = new ArrayList<T>(srcList.size());

        for (T t : srcList) {

            
展开阅读全文