Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java- Convert treeSet to List [duplicate]

Tags:

java

how can I convert this to a List of the same object type?

TreeSet<FieldBean> Fields = new TreeSet<FieldBean>();

Thanks

like image 598
Doc Holiday Avatar asked May 30 '12 13:05

Doc Holiday


People also ask

Does TreeSet allow duplicate?

TreeSet cannot contain duplicate elements. The elements in a TreeSet are sorted as per their natural ordering, or based on a custom Comparator that is supplied at the time of creation of the TreeSet. TreeSet cannot contain null value.

Does TreeSet allow heterogeneous objects?

TreeSet does not allow to insert heterogeneous objects because it must compare objects to determine sort order. TreeSet is not synchronized. If multiple threads access a hash set concurrently, and at least one of the threads modifies the set, it must be synchronized externally. Use Collections.

What is TreeSet in Java with examples?

TreeSet is one of the most important implementations of the SortedSet interface in Java that uses a Tree for storage. The ordering of the elements is maintained by a set using their natural ordering whether or not an explicit comparator is provided.


1 Answers

One of the constructors of ArrayList takes a collection as an argument and fills the list with the items contained in that collection:

List<FieldBean> list = new ArrayList<FieldBean> (fields);
like image 54
assylias Avatar answered Sep 25 '22 21:09

assylias