Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 5:09 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: method with a variable number of parameters
PostPosted: Fri Dec 12, 2008 9:56 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

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 */

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 HELP :Novel error tolerant method AES for satelite imgaes
 ordered list from specific number
 problem with JcheckBox method
 increase the number of bank lines by <br/>
 methods with variable arguments list
 validate international phone number value
 Factor of number using C++ code
 convert integer number to octal,hexadecimal number systems
 validation on number
 check if number is odd or even

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: Google Adsense [Bot] and 3 guests



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team