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();
}
}