Alex Rivera | Logout

Conversion from ArrayList to Collection

Asked 2012-02-05T03:35:02.180
9

I am having difficulty in this conversion. I don't know if there is a syntax error or this is not even possible.

I need to convert from--

private static final List<Contact> CONTACTS = Arrays.asList(
        new Contact("text1", "name1"),
        new Contact("text2", "name2"),
        new Contact("text3", "name3"));

To--

Collection c = new ArrayList(Arrays.asList(--?--))

--?-- --> (I don't understand what comes here)

By doing this, I intend to avoid UnsupportedOperationException. Any help appreciated, thanks!

Hey thank you all, i got it! This worked--
Solution:

List<? extends Contact> col = new ArrayList<Contact>(CONTACTS);
Edit
Report

1 Answer

2

Doing this works:

private static final Collection<String> c = new ArrayList<String>(
                                                Arrays.asList("a", "b", "c"));

Thus I'd suggest something like:

private static final Collection<Contact> = new ArrayList<Contact>(
                       Arrays.asList(new Contact("text1", "name1")
                                     new Contact("text2", "name2")));
answered 2012-02-05T03:51:30.177

Your Answer