Q:

create ArrayList with method and parameter is ArrayList's name

my question is simple, but haven't found answer anywhere, how can I create array like this:
public ArrayList<ArrayList<String>> result_of_query_into_array(
        ArrayList<String> nameofArray) {

    nameofArray = new ArrayList<String>();

    try {
        while (result.next()) {

            nameofArray.add(result.getString("nombre_estadio"));
            nameofArray.add(result.getString("ciudad"));
            nameofArray.add(result.getString("capacidad"));
            nameofArray.add(result.getString("temperatura"));
            nameofArray.add(result.getString("equipos"));

        }
    } catch (SQLException e) {

        JOptionPane.showMessageDialog(null,
                "Error en result.next().print..: " + e);
    }

    ARRAY_PRINCIPAL_MULTIDIMENSIONAL.add(nameofArray);

    JOptionPane.showMessageDialog(null, "got all rows  from table  ");

    return ARRAY_PRINCIPAL_MULTIDIMENSIONAL;

}

so when i use this method i have to do this : 
ArrayList<String> myArray = new ArrayList<String>();

obj.result_ofquery_into_array(myArray);

is  it posible   to just  do something like :
obj.result_of_query_into_array(myarrayWithoutInstantiatingOutside);

when i put just the name of the array i get an error : 
myarrayWithoutInstantiatingOutside cannot be resolved to a variable

please help,  thanks

A:

Because when you are passing a variable as an argument, you are in fact passing the reference of an object, which is then used. When not initializing a variable, you are passing and empty reference, which cannot be resolved. In your example, the correct way of doing this, since anyway you are overwriting the value of the variable, would be : 
public ArrayList<ArrayList<String>> result_of_query_into_array() {

    ArrayList<String> nameOfArray = new ArrayList<String>();

    // Logic...

    return nameOfArray;

}

And then just do :
myarrayWithoutInstantiatingOutside = obj.result_of_query_into_array();

Then, you are instantiating the object inside the method, and then returning the reference. 
Variables
You have to see variables as simple adresses. Let's take, for example, a house on a street. 
123 StackOverflow street
Now, this address, for you, might be your friend's address :
Adress myFriendAddress = 123 StackOverflow street
But for someone else, it might be his boss's address :
Adress myBossAddress = 123 StackOverflow street
The physical position of the house is the same, but the reference is different. It is the same way with objects and variables. The object has a memory address which is the physical position of the object in your memory.

