0
votes

could someone please explain to me how to create a large arraylist of objects currently, this is what i have.

public ArrayList particlecollection;

public ParticleColl(Particle thorium)
{
    particlecollection = new ArrayList<Particle>();

    for(int i=1;i<=100;i++)
    {
        particlecollection.add("Thorium",24.07);
    }
    System.out.println(particlecollection.get(3));
}

The particlecollection.add("Thorium",24.07) is referring to a Particle class, which has 2 paramaters

Particle(String name, double halflife)

The error that I am being given is "cannot find symbol- method add(java.lang.string,double); maybe you meant add(Particle) or add(int,Particle).

Thank you so much for your help in advance.

2

2 Answers

4
votes

That hasn't anything to do with the size of the array list. You forgot to construct your Particle object.

particlecollection.add(new Particle("Thorium",24.07));

Or quite possibly what you want is

particlecollection.add(thorium);
0
votes

The ArrayList can only add the object of the class which be used when the ArrayList is declared.

particlecollection.add(new Particle("Thorium",24.07));