java随笔

来源:互联网 发布:QQ中zz是什么意思网络 编辑:程序博客网 时间:2024/05/11 23:21
创建ArrayList的几种方法
1> 类Arrays 方法原型:
public static <T> List<T> asList(T... a) {
    return new ArrayList<T>(a);
    }
例如:
        List<String> weekList=Arrays.asList("sunday","monday","tuesday"
                            ,"wednesday","thursday","friday","saturday
");
此方法提供了一个创建固定长度的列表的便捷方法.

2>类Collections 方法原型:
public static <T> boolean addAll(Collection<? super T> c, T... a) {
        boolean result = false;
        for (T e : a)
            result |= c.add(e);
        return result;
    }
例如:
        ArrayList<String> weekList=new ArrayList<String>();
        String weeks[]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
        Collections.addAll(weekList,weeks);