Passing parametrized ArrayList to a function in java

Posted by user150505 on Stack Overflow See other posts from Stack Overflow or by user150505
Published on 2010-03-20T06:29:03Z Indexed on 2010/03/20 6:31 UTC
Read the original article Hit count: 360

Filed under:
|
|

I have the following fucntion.

func(ArrayList <String> name) { ........ }
The function fills the ArrayList. (I don't want to return the ArrayList)

However, in the caller function the ArrayList obtained has all items of ArrayList as null.
For eg.

1 name = new ArrayList[num];
2 func(name);
3 System.out.println(name[0]);

I get NullPointerException at line 3. Is this because of line 1, i.e. I am not parametrizing? If yes, is there another way this can be done? Because java does not allow creating a generic array of parametrized ArrayList.

© Stack Overflow or respective owner

Related posts about java

Related posts about arraylist