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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -