Java List Create createUnmodifiableList(Collection coll)

Here you can find the source of createUnmodifiableList(Collection coll)

Description

create Unmodifiable List

License

Open Source License

Declaration

public static <T> List<T> createUnmodifiableList(Collection<T> coll) 

Method Source Code

//package com.java2s;
/*****************************************************************************
 * Copyright (c) 2006-2013, Cloudsmith Inc.
 * The code, documentation and other materials contained herein have been
 * licensed under the Eclipse Public License - v 1.0 by the copyright holder
 * listed above, as the Initial Contributor under such license. The text of
 * such license is available at www.eclipse.org.
 *****************************************************************************/

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import java.util.List;

public class Main {
    public static <T> List<T> createUnmodifiableList(Collection<T> coll) {
        List<T> aList;//from  w  ww  .j av a  2  s . com
        if (coll == null || coll.size() == 0)
            aList = Collections.emptyList();
        else {
            List<T> newList;
            if (coll.size() == 1) {
                T value = (coll instanceof List<?>) ? ((List<T>) coll).get(0) : coll.iterator().next();
                newList = Collections.singletonList(value);
            } else
                newList = new ArrayList<T>(coll);
            aList = Collections.unmodifiableList(newList);
        }
        return aList;
    }
}

Related

  1. createTagList(List tags, String separator)
  2. createTarget(List labels)
  3. createTargetSorted(List labels, Comparator comp)
  4. createTuple(List> tuples, List entries, List> lists)
  5. createUniqueProducts(List list1, List list2)
  6. createUpdateMeasurementItemList(final String itemList, final String updateItem)
  7. createValues(int barCount, String valueDigits, int distributionType, List valueCounts)
  8. createWhereInClause(String field, List values, boolean isString)
  9. createWidList(int[][] widArray)