Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple parameters in List

Tags:

java

I want to do something like this

List<Integer, String, String>

I want to be able to iteratively retrieve either of these three parameters. How can I go about it? Thanks

like image 718
y2p Avatar asked Oct 20 '10 15:10

y2p


People also ask

How do you use multiple parameters?

Note that when you are working with multiple parameters, the function call must have the same number of arguments as there are parameters, and the arguments must be passed in the same order.

How do you add two parameters in Python?

In Python, by adding * and ** (one or two asterisks) to the head of parameter names in the function definition, you can specify an arbitrary number of arguments (variable-length arguments) when calling the function.

Can functions have multiple parameters?

Luckily, you can write functions that take in more than one parameter by defining as many parameters as needed, for example: def function_name(data_1, data_2):

How do you pass multiple arguments in Java?

Parameters are specified after the method name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma.


1 Answers

What you need is a Tuple class:

public class Tuple<E, F, G> {
    public E First;
    public F Second;
    public G Third;    
}

Then you can iterate over the list of the tuple, and look at each entry in the tuple.

List<Tuple<Integer, String, String> listOfTuple;
for (Tuple<Integer, String, String> tpl: listOfTuple){
    // process each tuple
    tpl.First ... etc
}
like image 171
jjnguy Avatar answered Nov 15 '22 16:11

jjnguy