title: Java - Access variable inside and outside of for-loop
body: <pre><code>String playerlist;
  
  for(Player p : allplayers){
      playerlist += p.getDisplayName() + ", ";
  }
  
  sendMessage(playerlist);
  </code></pre>
  
  <p>How can I accomplish this? I need to have a variable inside my for-loop, and then access it outside of the loop.</p>
  
  <p>Thanks, and sorry if this is a very nooby question. I just can't figure it out.</p>