Position: Document Download > All Categories > IT / Computer > Computer Software and Applications > Zhongguancun Beida Jade Bird: Java Variable Parameters
Infringement complaint

Zhongguancun Beida Jade Bird: Java Variable Parameters

[Type text]

Zhongguancun Beida Jade Bird 01062516562

Java variable parameters Java 1.5 adds new features: variable parameters: suitable for situations where the number of parameters is uncertain and the type is determined, java treats variable parameters as arrays. Note: The variable parameter must be the last item. When there is more than one variable parameter, there must be one that is not the last one, so only one variable parameter is supported. Because the number of parameters is indeterminate, when there are parameters of the same type behind it, java cannot distinguish whether the incoming parameter belongs to the previous variable parameter or the latter parameter, so only the variable parameter can be placed in the last item. Characteristics of variable parameters:

(1) It can only appear at the end of the parameter list;

(2), ... is located between the variable type and the variable name, with or without spaces before and after;

(3) When calling a method with a variable parameter, the compiler implicitly creates an array for the variable parameter, and accesses the variable parameter in the form of an array in the method body.

public class Varable {

public static void main (String [] args) {

System.out.println (add (2,3));

System.out.println (add (2,3,5));


public static int add (int x, int ... args) {

int sum = x;

for (int i = 0; i <args.length; i ++) {

sum + = args [i];


return sum;




Block C, 3 / F, Dahua Technology Commercial Building, 49 Zhongguancun Street, Haidian District

page 1

free download Word Document Free Download: Zhongguancun Beida Jade Bird: Java Variable Parameters

(Download 1-1 pages, total 1 pages)

you may also like

Back to top