编程语言

img zjz444

java随笔

发表于2008/9/29 10:54:00  229人阅读

创建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);



阅读全文
0 0

相关文章推荐

img
取 消
img