Total members 11890 |It is currently Fri Apr 19, 2024 5:13 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





In java J2SE0.5 you can now make a function with a variable number of paramters. The rules to do that is :

- Only varaible paramter list only .
- varaible paramter list must apper in the last inside the parentheses of the function.
- defined as : type followed by three dots and the name .

And example about method with a variable number of parameters.
Code:
import java.io.*;
class MyClass {
public void printStuff(String greet, int... values) {
for (int v : values ) {
System.out.println( greet + ":" + v);
}
}
}
class VarargTest {
public static void main(String[] args) {
MyClass mc = new MyClass();
mc.printStuff("Hello", 1);
mc.printStuff("Hey", 1,2);
mc.printStuff("Hey you", 1,2,3);
}
}

/* code taken from apress SCJP 1.5 */




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : method with a variable number of parameters
 Method Parameters,,,is it by value or reference???     -  
 pass parameters to main method args[] variables     -  
 different between Local variable and Global variable     -  
 convert integer number to octal,hexadecimal number systems     -  
 convert octal number to decimal number     -  
 convert decimal number to octal number     -  
 PHP variable in javascript     -  
 transient variable     -  
 Encoding parameters in URL     -  
 Reference Parameters     -  



Topic Tags

Java Methods
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com