Wednesday, September 18, 2013

How do I invoke a method that takes a "Collection

How do I invoke a method that takes a "Collection

The method signature looks like this:
public void addThemAll(Collection<? extends T> c)
Which essentially just adds every element of the collection to my
LinkedList. But I keep trying to feed this method an Array or a Linked
List and I always get an error. For example:
double[] myarray = new double[]{3.4, 4.5, 8.6};
mylist.addThemAll(myarray);
I'm sure this is something straightforward, but I can't find an example
online that just passes an array/linked list into a method like this.

No comments:

Post a Comment