I am taking a Class on Java, and sadly the professor is not all that good. But we have a project to do...

I have got to a point where I need to pull info out of an arraylist...
But it is an arraylist that is made up of arraylists.
playerinfo = [ [info #1], [info #2],[info #3] ]
The problem I am having is pulling the arraylists inside, out.

Here is the code...
playerinfo is the main arraylist as explained above.

ArrayList player1= new ArrayList(playerinfo.get(0));

However I am getting this error.
" cannot find symbol constructor ArrayList(java.lang.Object) "

Any help would be greatly appreciated.

7 Years
Discussion Span
Last Post by Beasts

You just need to "get()" the info that is there. The code you posted is trying to create a new ArrayList.

It looks more like you want playerinfo.get(0).get(0) .


Yes, I need to pull the arraylist out and into a new arraylist.
I was able to do it, by creating a new arraylist, then
But that gave me [[info #1]]
So there was an arraylist in an arraylist... the reason I need to pull that inner arraylist out is it will have an unknown amount of elements inside that I need to check, and see if they match a user inputted integers(so [info#1] could be filled with [3,12,65,1,16]) . Hopefully that makes sense.
So this code is running in a for loop nested in another for loop.
If there is an easier way to scan the arraylist and pull the inside arraylist’s elements out I’m all for it if u know one.

Thanks again.


You access that inner array list just like I indicated above. I still don't understand why you need to create a new one, but then I don't know what you're trying to do with that structure. Here's a loop that will print each element, maybe that will help answer your question.

ArrayList playerinfo = new ArrayList();
for (int i=0; i< playerinfo.size(); i++){
    ArrayList innerList = (ArrayList)playerinfo.get(i);
    for (int j=0; j<innerList.size(); j++){
        System.out.println( innerList.get(j).toString() );

If your ArrayLists are declared with generics, you won't need the cast.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.