0

I want to make 4 classes for 4 players. So i thought that it can be easily fixed with a for loop.

for(int i = 0; i<playerlist.size(); i++){
    PlayerStats player+i = new PlayerStats(playerlist.get(i),app,0f,135f,190f,100f);
    app.addGameObject(player+i);
    }

This does not work.. Has anyone a solution for this problem?

Thanks in advance!

  • An array of length 4. – Elliott Frisch Mar 25 '16 at 13:52
  • Java doesn't allow for dynamic naming of variables nor is it needed. As @ElliottFrisch states, use an array or the more flexible ArrayList, here an `ArrayList`. – Hovercraft Full Of Eels Mar 25 '16 at 13:53
  • For more on this and similar questions, please have a look at [this link](https://www.google.com/webhp?sourceid=chrome-instant&rlz=1C1LEND_enUS445US445&ion=1&espv=2&ie=UTF-8#q=java+dynamic+name+variable+site:http:%2F%2Fstackoverflow.com%2F). The first few hits ought to be what you need. – Hovercraft Full Of Eels Mar 25 '16 at 13:54

0 Answers0