528 questions
3495
votes
28
answers
1.5m
views
What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
What do *args and **kwargs mean in these function definitions?
def foo(x, y, *args):
pass
def bar(x, y, **kwargs):
pass
See What do ** (double star/asterisk) and * (star/asterisk) mean in a ...
426
votes
17
answers
587k
views
Variable number of arguments in C++?
How can I write a function that accepts a variable number of arguments? Is this possible, how?
80
votes
11
answers
54k
views
Arrays.asList() not working as it should?
I have a float[] and i would like to get a list with the same elements. I could do the ugly thing of adding them one by one but i wanted to use the Arrays.asList method. There is a problem though. ...
1057
votes
9
answers
628k
views
What do 3 dots next to a parameter type mean in Java?
What do the 3 dots following String in the following method mean?
public void myMethod(String... strings) {
// method body
}
208
votes
8
answers
176k
views
When do you use varargs in Java?
I'm afraid of varargs. I don't know what to use them for.
Plus, it feels dangerous to let people pass as many arguments as they want.
What's an example of a context that would be a good place to ...
376
votes
6
answers
325k
views
Can I pass an array as arguments to a method with variable arguments in Java?
I'd like to be able to create a function like:
class A {
private String extraVar;
public String myFormat(String format, Object ... args){
return String.format(format, extraVar, args);
}
}
...
365
votes
11
answers
215k
views
Passing variable number of arguments around
Say I have a C function which takes a variable number of arguments: How can I call another function which expects a variable number of arguments from inside of it, passing all the arguments that got ...
208
votes
12
answers
167k
views
Is it possible to send a variable number of arguments to a JavaScript function?
Is it possible to send a variable number of arguments to a JavaScript function, from an array?
var arr = ['a','b','c']
var func = function()
{
// debug
alert(arguments.length);
//
...
83
votes
11
answers
41k
views
Spread Syntax vs Rest Parameter in ES2015 / ES6
I am confused about the spread syntax and rest parameter in ES2015. Can anybody explain the difference between them with proper examples?
185
votes
12
answers
178k
views
Passing variable arguments to another function that accepts a variable argument list
So I have 2 functions that both have similar arguments
void example(int a, int b, ...);
void exampleB(int b, ...);
Now example calls exampleB, but how can I pass along the variables in the variable ...
188
votes
8
answers
110k
views
Passing an array to a function with variable number of args in Swift
In The Swift Programming Language, it says:
Functions can also take a variable number of arguments, collecting them into an array.
func sumOf(numbers: Int...) -> Int {
...
}
When I ...
468
votes
21
answers
262k
views
How can I convert the "arguments" object to an array in JavaScript?
The arguments object in JavaScript is an odd wart—it acts just like an array in most situations, but it's not actually an array object. Since it's really something else entirely, it doesn't have the ...
377
votes
11
answers
216k
views
Why use the params keyword?
I know this is a basic question, but I couldn't find an answer.
Why use it? if you write a function or a method that's using it, when you remove it the code will still work perfectly, 100% as without ...
212
votes
13
answers
111k
views
How to properly match varargs in Mockito
I've been trying to get to mock a method with vararg parameters using Mockito:
interface A {
B b(int x, int y, C... c);
}
A a = mock(A.class);
B b = mock(B.class);
when(a.b(anyInt(), anyInt(), ...
105
votes
7
answers
159k
views
How to pass variable number of arguments to printf/sprintf
I have a class that holds an "error" function that will format some text. I want to accept a variable number of arguments and then format them using printf.
Example:
class MyClass
{
public:
...