String... java
//Object... (here String...) means that you can give
//in parameter one or many objects of same type
func();
func("arg1", "arg2", "arg3");
String[] args = new String[]{"arg1", "arg2", "arg3"}
func(args);
void func(String... args);
String... java
//Object... (here String...) means that you can give
//in parameter one or many objects of same type
func();
func("arg1", "arg2", "arg3");
String[] args = new String[]{"arg1", "arg2", "arg3"}
func(args);
void func(String... args);
string = new string
public class VarargsExample {
public static void main(String[] args) {
// Example 1: Calling func with no arguments
func();
// Example 2: Calling func with three String arguments
func("arg1", "arg2", "arg3");
// Example 3: Creating an array and passing it to func
String[] argArray = new String[]{"arg1", "arg2", "arg3"};
func(argArray);
}
// Varargs method that accepts a variable number of String arguments
static void func(String... args) {
System.out.println("Number of arguments: " + args.length);
for (String arg : args) {
System.out.println("Argument: " + arg);
}
System.out.println();
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us