Pass Arraylist as argument to function


I have an arraylist A of Integer type. I created it as:

ArrayList<Integer> A = new ArrayList<Integer>();

Now, I want to pass it as an argument to function AnalyseArray().

How can I achieve this?

This question is tagged with java arraylist

~ Asked on 2013-06-15 15:38:16

The Best Answer is


public void AnalyseArray(ArrayList<Integer> array) {
  // Do something
ArrayList<Integer> A = new ArrayList<Integer>();

~ Answered on 2013-06-15 15:40:55


The answer is already posted but note that this will pass the ArrayList by reference. So if you make any changes to the list in the function it will be affected to the original list also.

<access-modfier> <returnType> AnalyseArray(ArrayList<Integer> list)
//analyse the list
//return value

call it like this:


or pass a copy of ArrayList:


~ Answered on 2013-06-15 15:45:27

Most Viewed Questions: