How convert a Set into a List

Given the following :

Set<Student> students = getStudents() ;

how would one convert the set students

to a List<Students>

I was thinking of doing something like :

Student[] array = students.toArray(new Student [students.size()]);

List<Student> list=Arrays.asList(array);

but it doesn't work

[391 byte] By [jmutonhoa] at [2007-11-27 2:23:47]
# 1
List has an "addAll()" method that looks useful to you
tsitha at 2007-7-12 2:29:50 > top of Java-index,Java Essentials,Java Programming...
# 2
List<Student> list = new ArrayList<Student>(getStudents());
prometheuzza at 2007-7-12 2:29:50 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks.Out of interest though (as a theoretical exercise), if one was to use the Arrays.asList how would it be done?
jmutonhoa at 2007-7-12 2:29:50 > top of Java-index,Java Essentials,Java Programming...
# 4

> Thanks.Out of interest though (as a theoretical

> exercise), if one was to use the

>

> Arrays.asList

>

> how would it be done?

Try this:

Set<Student> set = getStudents();

Student[] array = set.toArray(new Student[set.size()]);

List<Student> list = Arrays.asList(array);

prometheuzza at 2007-7-12 2:29:50 > top of Java-index,Java Essentials,Java Programming...
# 5
That's what I had initially ( refer to my first post) but somehow Eclipse was complaining that I could not create a an array of generic types.When I try it now , the error is gone
jmutonhoa at 2007-7-12 2:29:50 > top of Java-index,Java Essentials,Java Programming...