user2829699
user2829699

Reputation: 1

how to take an arraylist of string type from one method to another method

I am a couple of semesters into learning java and I am looking to move an arraylist from one method to another. I have look everywhere but could not find exactly what I need. Thank you.

public static void addEmployee(ArrayList<String> list)
{
    int i;                  //declares i as integer

    //increments i for the array
    for(i = 0; i < list.size(); i++)
        list.get(i);        //adds employees to an arraylist

    for(i = 0; i < list.size(); i++)
        addEmployee(list.get(i)); //This does not work

}//end public static void addEmplyoee(Arraylist<String> list)

public static void searchId(ArrayList<String> list)
{

}

Upvotes: 0

Views: 44

Answers (1)

AbdullahC
AbdullahC

Reputation: 6730

You need to pass the ArrayList as a reference:

searchId(list);

That is, don't pass just a single element using ArrayList.get().

Upvotes: 1

Related Questions