开发者

What is the use of var-args in Java? [duplicate]

开发者 https://www.devze.com 2023-03-01 03:11 出处:网络
This question already has answers her开发者_高级运维e: Closed 11 years ago. Possible Duplicate: java: how can i create a function that supports any number of parameters?
This question already has answers her开发者_高级运维e: Closed 11 years ago.

Possible Duplicate:

java: how can i create a function that supports any number of parameters?

I don't understand the concept of var-args. Please explain them to me with a simple example.


They just give you an easy way to pass an undefined number of arguments (all of the same type) to a function. All it's really doing is creating an array out of the arguments you pass in, but it makes it so you don't need to write all the code to create an array and add elements to it. Instead, you just pass the arguments as "extra" arguments to the method.

0

精彩评论

暂无评论...
验证码 换一张
取 消