Java: Are these 2 codes the same?

Posted by Kevin Duke on Stack Overflow See other posts from Stack Overflow or by Kevin Duke
Published on 2010-03-11T03:23:32Z Indexed on 2010/03/11 4:39 UTC
Read the original article Hit count: 209

Filed under:
|
for (Player p : players) 
{
  p.addCard(deck.dealCard());
  p.addCard(deck.dealCard());
}

and

  for (int i = 0; i < players.size() ; i++)
{
    Player p = players.get(i);
    p.addCard(deck.dealCard());
    p.addCard(deck.dealCard());
}

The second code yeilds a null pointer exception, what can be done to make the bottom one equivalent ?

© Stack Overflow or respective owner

Related posts about java

Related posts about foreach