Alex Rivera | Logout

Passing a string array as a parameter to a function java

Asked 2012-07-28T04:27:43.933
14

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.

Edit
Report

2 Answers

3

I believe this should be the way this is done...

    public static void function(String [] array){
    ...
    }

And the calling will be done like...

    public void test(){
        String[] stringArray = {"a","b","c","d","e","f","g","h","t","k","k","k","l","k"};
        function(stringArray);
    }
answered 2012-07-28T04:31:06.303
0

look at familiar main method which takes string array as param

answered 2012-07-28T05:52:31.207

Your Answer