0

I am new to Java and got to access a legacy app that has a method like this which takes variable number of arguments.

  MarkEdges(edge1,edge2,edge3...){...}

where:

 Edge edge1 = new Edge(/*edge arguments go here*);

it works fine like that but I have a list of edges that I want to pass to MarkEdges:

 List<Edge> edges = new ArrayList();
 //populate the edges from a service then pass them for marking.
 MarkEdges(edges);

but I can't compile it. I was hoping for something like spread operator of JS.

khelwood
  • 55,782
  • 14
  • 81
  • 108
ruth hadish
  • 49
  • 1
  • 4
  • You don't have an array, but a List ;) you wrote well in title, but mistake in post – azro Jan 06 '22 at 20:35

1 Answers1

1

You have to use

MarkEdges(edges.toArray(new Edge[0]));
Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413