Ans : It is a new feature in java 1.5 [ also called as tiger ]
Example : public static void mymethod(String ... objects)
{
for(String s : myString)
{
Syso("String : "+s);
}
}
Note : variable number of arguments type statements should be last argument in the
method definition.
Example :
This code is correct :
int n = 43000;
int number = 500;
String name = "sekhae23";
String myName = "Karri,sekhar";
myMethod(n,number,myName,name);
public static void myMethod(int x,int y,String ... objects){
//Observer variable number of arguments argument is last ....
for(String s : objects){
System.out.println(" S >>>> "+s);
}
System.out.println(" ");
}
Below code snippet is Wrong :
int n = 43000;
String myName = "Karri,sekhar";
String name = "sekhae23";
int number = 500;
myMethod(myName,name,n,number);
public static void myMethod(String ... objects,int x,int y){
//Observer variable number of arguments argument is last ....
for(String s : objects){
System.out.println(" S >>>> "+s);
}
System.out.println(" ");
}
Observation : One Method can have only one variable number of arguments argument.
No comments:
Post a Comment