Is there any difference between string… Args and string [] args in Java?

See English answer > difference FN (string... Args) vs FN (string [] args) 6

I am a novice in Java programming Anyone can tell me (string... Args) & what's the difference? (string [] args) if I replace the second with the first What's the difference?

String... Args will declare a method that requires a variable number of string parameters The number of parameters can be anything: including zero

String [] args and the equivalent string args [] will declare a method that requires only one parameter: an array of strings

One difference that may not arise from these observations is that in the second case (but not the first), the caller may have a reference to the array In both cases, the method uses args as a string array, but if it performs operations such as exchanging array elements, if it uses the form of string... Args, the caller will not be able to see it

Solution

If you have a void x (string... Args) method, you can call it x ("1", "2", "3"), while void x (string [] args) can only be called X (new string [] {"1", "3"})

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>