Error traversing ArrayList java

0
    private ArrayList GetIC (){
    ArrayList<Sorpresa> molde;
    molde = new ArrayList <>();

    for (Sorpresa t : juego.getMazo()){
        if (t.GetTipo() == TipoSorpresa.IRACASILLA){
            molde.add(new Sorpresa(t.GetTexto(),t.GetValor(),t.GetTipo()));
        }
    }


    return molde;
}

Surely my mistake is an outrage because I am a beginner, thank you.

    
asked by Master cabesa 22.09.2018 в 17:15
source

1 answer

1

It would give your code more versatility to use the List interface instead of ArrayList.

List <Sorpresa> molde;

Also emphasize what A.Cedano says, is the game object implemented?

And why do you create a new object Sorpresa if the foreach is already giving you one, instead of:

molde.add(new Sorpresa(t.GetTexto(),t.GetValor(),t.GetTipo()));

You could do this:

molde.add(t);

    
answered by 22.09.2018 / 20:46
source