Dacto Dacto - 18 days ago 5
Java Question

pass array to method Java

How can I pass an entire array to a method?

private void PassArray() {
String[] arrayw = new String[4];
//populate array

private void PrintA(String[] a) {
//do whatever with array here

How do I do this correctly?


You do this:

private void PassArray(){
    String[] arrayw = new String[4]; //populate array

private void PrintA(String[] a){
    //do whatever with array here

Just pass it as other variable. In Java, Arrays are passed by reference.