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.
2
Q
How many varargs can we have in a parameter list?
A
You are allowed to have only one varargs parameter per method.
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.
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
5
Q
How to access a varargs parameter?
A
Accessing a varargs parameter is just like accessing an array.