Converting an Array to a Collection
Sometimes the common problems seems to be we don’t remember the API, one such scenario I recently faced was how to convert a Array to a collection? Following seems to decent ways
// Fixed-size list
List list = Arrays.asList(array);
// Growable list
list = new LinkedList(Arrays.asList(array));
// Duplicate elements are discarded
Set set = new HashSet(Arrays.asList(array));
Written by Ravi Nallakukkala on November 29th, 2007 with
no comments.
Read more articles on Java/ J2EE.
- [+] Digg: Feature this article
- [+] Del.icio.us: Bookmark this article
- [+] Furl: Bookmark this article