1

I have this AVL tree with a balance method:

private void setBalance(Node... nodes) {
    for (Node n : nodes)
        n.height = height(n.right) - height(n.left);
}

It uses a (...) syntax I have not encountered before. I can't find it on google or SO. It seems to be some type of list syntax, or array. Looks like something I would find in ruby.

Could someone knowledgeable in Java's syntax explain this code to me, and perhaps show me a version without the ... syntax?

Thanks.

user2864740
  • 60,010
  • 15
  • 145
  • 220
user3098364
  • 63
  • 1
  • 5
  • 1
    You can treat `Node...` as `Node []`, or just change the `Node...` to `Node []` and `setBalance` will still work. Take a look at the [Arbitrary Number of Arguments](https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html). – Watermel0n Jul 14 '15 at 01:20

1 Answers1

7

These are varargs . Basically same are arrays but can be zero to many. More info that might also assist.

Community
  • 1
  • 1
Shahzeb
  • 4,745
  • 4
  • 27
  • 40