Log in

View Full Version : Java: using an array from the main in a method


kilroy
Jul 23, 2003, 08:04 AM
I have the array names[][] in the main of my program and I want to use it in a method FindName..
How would I wright the method header and the call to the method in the main?

kilroy
Jul 23, 2003, 08:44 AM
The array is a string array

Deschwann
Jul 30, 2003, 12:37 PM
OK, first of all you can't call the method directly from the main unless your method is static.

example

public class className{

static method(String[][] name){

}

public static void main(String args[]){

String name[][];
//fill the string here
method(name);
}
}

your second choice is to make an object of your class and use the method

public class className{

public method(String[][] name){

}

public static void main(String args[]){

String name[][];
//fill the string here

className copyOfClass = new className();
copyOfClass.method(name);
}
}