This is Java, not Javascript. Moving to Java forum.
Short answer is you cannot. ArrayList is an instance and as such will be scoped to where it is declared. So unless ArrayList is declared within Molecule (make it static if its shared), then you'll need to pass ArrayList<Atom> as a parameter to any method that uses it.
As for your createAtoms method itself, you cannot do that at all. new Atom cannot be assigned the value of atomA (wherever that is declared). What you want is to fetch from it, but to do so you need to iterate it.
PHP Code:
public void createAtoms(int protons, ArrayList<Atom> atoms) // not sure if this signature is right. This is already an instance, so I don't know what createAtom's purpose is since it doesn't return a result
{
Atom oChosen = null;
for (Atom a : atoms)
{
if (a.myProtons == protons) // not sure if this is right either since you don't have Atom class declaration here.
{
oChosen = a;
break;
}
}
// now I don't know what you want to do with it.
}
An overall way around this is to declare the arraylist as static somewhere where it is within scope that molecules can access it. I'd probably just declare it and pass it into the constructor.
Edit:
BTW, one other way to get around this is to make the "collection" of possible atoms as a static property in the Atom class itself. Make the constructor private and use a static createInstance to handle it. If it already has it in the list, just pull that instead of creating a new instance. This way it will always be the same instance of an Atom that is equatable instead of multiple instances of Atoms with the same data.