Answers for "string = new string"

-1

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);
Posted by: Guest on July-06-2020
1

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();
    }
}
Posted by: Arsalan malik on February-09-2024

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language