传递一个字符串数组作为参数传递给函数的java [英] Passing a string array as a parameter to a function java
本文介绍了传递一个字符串数组作为参数传递给函数的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,f,g,h,t,k,k,k,l,k};
function(stringArray);
instead of
function(a,b,c,d,e,f,g,h,t,k,k,k,l,k);
但是,如果我这样做,我得到一个错误,指出转换的String []转换成String。我想知道,是否有可能通过这样或什么是做到这一点的正确方法的值。谢谢你。
But if I do this I am getting an error stating that convert String[] into String. I would like to know, is it possible to pass the values like this or what is the correct way to do this. Thank you.
推荐答案
如何
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);
}
}
这篇关于传递一个字符串数组作为参数传递给函数的java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文