0

I have a method that takes a variable argument list.

getSome(Object... numbers);

I have a List holding all the parameters that I want to pass to the method.

ArrayList<Long> numbersList;

How can I achieve the following for ALL number objects in the list?

getSome(numbersList.get(0), numbersList.get(1), ... numbersList.get(numbersList.size()-1));
assylias
  • 321,522
  • 82
  • 660
  • 783
user1414745
  • 1,317
  • 6
  • 25
  • 45
  • 2
    How about `getSome(numbersList.toArray())` or `getSome(numbersList.toArray(new Long[numbersList.size()]))`? – Pshemo Jul 23 '13 at 15:38
  • You should rewrite `getSome` to take a `List` then or add an overloaded method. why does your version take `Object...`? – Eric Jablow Jul 23 '13 at 16:24

2 Answers2

2

You can transform your list into an array:

getSome(numbersList.toArray(new Long[numbersList.size()]));
assylias
  • 321,522
  • 82
  • 660
  • 783
0

Given the method declaration :

getSome(Object... numbers);

You can pass an array to it.

You can use the List#toArray() method to transform the List to an Long[]:

numbersList.toArray(new Long[numbersList.size()]);
AllTooSir
  • 48,828
  • 16
  • 130
  • 164