7.2_Working with Varargs Flashcards

1
Q

What position should a varargs parameter take?

A

Varargs parameter must be the last element in a method’s parameter list.

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

How many varargs can we have in a parameter list?

A

You are allowed to have only one varargs parameter per method.

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

What possibilities do we have when calling a method with varargs?

A
  • > We can pass in an array

- > or we can list the elements of the array and let Java create it for us.

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

⚠️🤯️ What happens when no elements/array/null are passed as the varargs argument?

A
  • > Java will create an empty array if no parameters are passed for a vararg. (An array of length 0)
  • > However, it is still possible to pass null explicitly -> This could throws a NPE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to access a varargs parameter?

A

Accessing a varargs parameter is just like accessing an array.

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