Refering to parameter position

Hello

Is there an equivalent in Java of the "@_" variable in Perl for referring to different parameters.

I would like to do something like this

publicvoid assign(int firstNumber,int secondNumber,int thirdNumber)

{

for(int i=0; i<3; i++)

System.out.println(firstNumber);

// Second Iteration

// Print out value of second parameter(secondNumber)

// Thid Iteration

// Print out the value of the third parameter(thirdNumber)

}

Hope someone can help

[938 byte] By [ANDREWP7a] at [2007-11-27 4:05:57]
# 1
didn't really get what you want to do, but you can try that:int[] params = new int[]{firstNumber, secondNumber, thirdNumber};and then you can loop over params array
calvino_inda at 2007-7-12 9:10:58 > top of Java-index,Java Essentials,Java Programming...
# 2

No.

You could do

public void assign(int numbers... )

//or

public void assign(int[] numbers )

mlka at 2007-7-12 9:10:58 > top of Java-index,Java Essentials,Java Programming...
# 3

Google for "java Variable-Length Argument Lists" to find examples and tutorials about this feature of java 5.0.

You could then write a method as follows:

public void assign(int... numbers) {

for (int i: numbers) {

System.out.println(i);

}

}

martin@worka at 2007-7-12 9:10:58 > top of Java-index,Java Essentials,Java Programming...