Return a collection as Constant List - Java java.util

Java examples for java.util:Collection Search

Description

Return a collection as Constant List

Demo Code


//package com.java2s;
import java.util.*;

public class Main {
    public static <T> List<T> asConstList(T... in) {
        return Collections.unmodifiableList(Arrays.asList(Arrays.copyOf(in,
                in.length)));/*from  w w w  .  ja v a  2  s  . c  om*/
    }

    public static <T> List<T> asConstList(Collection<T> in) {
        ArrayList<T> ret = new ArrayList(in);
        ret.trimToSize();
        return Collections.unmodifiableList(ret);
    }
}

Related Tutorials