Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a string array as a parameter to a function java

I would like to pass a string array as a parameter to a function. Please look at the code below

String[] stringArray = {'a', 'b', 'c', 'd', 'e'};

functionFoo(stringArray);

Instead of:

functionFoo('a', 'b', 'c', 'd', 'e');

but if I do this I am getting an error stating that convert String[] into String. I would like to know if it is possible to pass the values like that or what is the correct way to do it.

like image 836
NandaKumar Avatar asked Jul 28 '12 04:07

NandaKumar


1 Answers

How about:

public class test {
    public static void someFunction(String[] strArray) { 
        // do something 
    }

    public static void main(String[] args) {
        String[] strArray = new String[]{"Foo","Bar","Baz"};
        someFunction(strArray);
    }
}
like image 103
Jubal Avatar answered Nov 06 '22 19:11

Jubal