Java object not added to ArrayList -


i have problem. writing code ecosystem fish , trying add new fish object existing fish arraylist . however, when check arraylist turns out empty? thoughts?

public void addfish(fish f){     arraylist<fish> fishplusone = new arraylist<fish>(fish.size());     if (landscape[f.getrow()][f.getcol()] != rock) {         (fish otherfish: this.fish) {                 if(otherfish.getrow() == f.getrow() && otherfish.getcol() == f.getcol()) {                     throw new illegalfishpositionexception(illegalfishpositionexception.two_fish_in_one_place);                   }                 else {                     fishplusone.add(otherfish);                      }                 fishplusone.add(f);                 fish = fishplusone;                 }              } 

you create new arraylist each time: arraylist<fish> fishplusone = new arraylist<fish>(fish.size());

isn't easier checks first , add existing list?


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -