如何将整个数组传递给方法?
private void PassArray() {
String[] arrayw = new String[4];
//populate array
PrintA(arrayw[]);
}
private void PrintA(String[] a) {
//do whatever with array here
}
我该如何正确地做到这一点?
最佳答案
你这样做:
private void PassArray() {
String[] arrayw = new String[4]; //populate array
PrintA(arrayw);
}
private void PrintA(String[] a) {
//do whatever with array here
}
只需将其作为任何其他变量传递即可。
在 Java 中,数组是通过引用传递的。
关于java - 将数组传递给 Java 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1610757/