I am trying to allocate a random ArrayList array with size elements, fill with random values between 0 and 100
This is the block that I keep getting the error in
public static ArrayList<Integer> generateArrayList(int size)
{
// Array to fill up with random integers
ArrayList<Integer> rval = new ArrayList<Integer>(size);
Random rand = new Random();
for (int i=0; i<rval.size(); i++)
{
rval.get(i) = rand.nextInt(100);
}
return rval;
}
I've tried the .set and .get methods but neither of them seem to work
I keep getting the error unexpected type required: variable; found: value
It is throwing the error at .get(i)
=sign you need a value. On the left side you need a variable. A variable is (usually) a value, but not vice-versa.new ArrayList<Integer>(size)will create anArrayListwithsizeelements in it. It doesn't: it creates an empty list with capacity forsizeelements. (And in any case the capacity will grow as needed, so you don't usually have to worry about it.)