I am trying to create a 2d array list but it is giving me a compiler error pointing at the first line of the function. I don't really get what is causing the problem. I am pretty good in C++ but Java has some new rules that I am trying to learn. Does anyone see a problem here?

Code:

void addToList(int[] a, int j, int i, int N)            
{
	ArrayList< ArrayList<int> > perms = new ArrayList<ArrayList<int>>();
	for(int x = 0; x < N; x++) {
		perms.add(new ArrayList<int>());
		perms.get(perms.size()-1).add(a[x]);
		System.out.print(a[x]);
	}
	System.out.println("   swapped(" + j + ", " + i + ")");
} // addToList()

Error:

MiniMaxTree.java:119: unexpected type
found   : int
required: reference
                ArrayList< ArrayList<int> > perms = new ArrayList<ArrayList<int>>();
                                ^
MiniMaxTree.java:119: unexpected type
found   : int
required: reference
                ArrayList< ArrayList<int> > perms = new ArrayList<ArrayList<int>>();

Thanks in advance!

Edited 7 Years Ago by chunalt787: n/a

So I would have to make a wrapper class myInt which stores an int as its data member?

There are existing wrapper classes for all of the primitive types.
Use Integer. Auto-boxing will handle the casting for you.

Edited 7 Years Ago by Ezzaral: n/a

This question has already been answered. Start a new discussion instead.