Find existing player to update or create new one
A very quick review for the code, and assuming Java &lt; 8:

public void handleNewPlayer(Player newPlayer, Player[] otherPlayers) {
    for (Player otherPlayer : otherPlayers) {
        if (newPlayer.id == otherPlayer.id) {
            updatePlayer(otherPlayer);
            return;
        }
    }

    createPlayer(newPlayer);
}


Some code styles prohibit this because you typically only want to have one return in a function (there's two here), but I typically overlook this for simple methods where the logic ends up clearer in my opinion.

And here's a Java 8 way (might not be optimal)

public void handleNewPlayer(Player newPlayer, Player[] otherPlayers) {
    final Optional&lt;Player&gt; otherPlayer = Arrays.stream(otherPlayers)
        .filter((Player p) -&gt; newPlayer.id == p.id)
        .findFirst();

    if (otherPlayer.isPresent()) {
      updatePlayer(otherPlayer.get());
    }
    else {
      createPlayer(newPlayer);
    }
}


It doesn't do much on the LOC metric, but it has a much clearer semantic meaning.

A comment from Vogel612 brings up the Optional#orElse method. This sounds like a great method, but the only way I can see it used here is as follows:

public void handleNewPlayer(Player newPlayer, Player[] otherPlayers) {
    final Optional&lt;Player&gt; player = Arrays.stream(otherPlayers)
        .filter((Player p) -&gt; newPlayer.id == p.id)
        .findFirst()
        .orElse(newPlayer);

    if (newPlayer == player) {
      createPlayer(newPlayer);
    }
    else {
      updatePlayer(player);
    }
}


I think this has even greater semantic meaning, but your mileage my vary. Additionally, I still feel like we're lacking the conciseness of the final version below.

Finally, you can now use Groovy for Android development. Here's how this can be done in Groovy:



def handleNewPlayer(Player newPlayer, Player[] otherPlayers) {
  def otherPlayer = otherPlayers.find() { newPlayer.id == otherPlayer.id }
  if (otherPlayer) {
    updatePlayer otherPlayer
  }
  else {
    createPlayer newPlayer
  }
}