4 Working with varags Flashcards

1
Q

Where must the varag be in the method parameters?

A

a method may use a vararg parameter (variable argument)
as if it is an array. It is a little different than an array, though. A vararg parameter
must be the last element in a method’s parameter list. This implies you are only allowed to
have one vararg parameter per method.

public void walk1(int… nums) { }
public void walk2(int start, int… nums) { }
public void walk3(int… nums, int start) { } // DOES NOT COMPILE
public void walk4(int… start, int… nums) { } // DOES NOT COMPILE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

x

A

When calling a method with a vararg parameter, you have a choice. You can pass in an
array, or you can list the elements of the array and let Java create it for you. You can even
omit the vararg values in the method call and Java will create an array of length zero for
you.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly