Dacto Dacto - 1 year ago 99
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download