user3502692
user3502692

Reputation: 3

create a large arraylist

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.

Upvotes: 0

Views: 773

Answers (2)

we1559
we1559

Reputation: 26

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));

Upvotes: 0

Paul Hicks
Paul Hicks

Reputation: 13999

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);

Upvotes: 4

Related Questions