Why are we mentioning as Node  in all.toArray(newNode)), when I checked for the syntax it is suggesting as size of array but we are passing 0 in new Node. Please clarify on this
Course: The Ultimate Data Structures and Algorithms: Part 3
Topic: Graphs (Cycle Detection in directed graphs)
toArray() method without parameters returns an array of
Objects. Usually you want a more specific return type and can specifiy that return type as the first argument. In this case you want an array of
Nodes so you provide an array of
Nodes as an argument. Since this is just used to determine the result type it’s ok to supply an empty array of the desired type.
And yes, that is a very ugly construction. That’s why Mosh shows you a better way just a few seconds later. And don’t worry if that looks weird to you, too. All you need to understand for this course is that the code returns the first element of the set.
Thanks for the explanation.