title: Updating an arraylist if the object exists
body: <p>Need some help on how to update a list. I've got a class which defines the object with string name, string status, float lat and float long.</p>
  
  <p>Every time a player moves a server sends me an asynchronous message whit these variables, the only thing changing can be status lat and long which are the ones I want to "overwrite". The name is unique so I'm guessing I have to search based on that as that's the thing never changing. I want to update the existing object to prevent one player from occurring more then once.</p>
  
  <p>My (non functional) code so far:</p>
  
  <pre><code>    if(players.size()==0){ ///// 1.
                          Player p  = new Player();
                          p.name = split[2];
                          p.status = split[3];
                          p._lat = Float.valueOf(split[4]);
                          p._long = Float.valueOf(split[5]);
                          players.add(p);
                      }//This works
  
  
                      else{ ///// 2.
                      for(int i = 0; i &lt; players.size(); i++){ ///// 3.
                          if(players.get(i).name.equals(split[2])){
                              Player p  = new Player();
                              p.name = split[2];
                              p.status = split[3];
                              p._lat = Float.valueOf(split[4]);
                              p._long = Float.valueOf(split[5]);
                              players.add(p);
                              players.add(i, p);
                          }
                          else{ ///// 4.
                              Player p  = new Player();
                              p.name = split[2];
                              p.status = split[3];
                              p._lat = Float.valueOf(split[4]);
                              p._long = Float.valueOf(split[5]);
                              players.add(p);
                          }
                      }//This doesnt
                      }
  </code></pre>
  
  <p>It's probably something obvious but I don't really know how to search and replace an object. The functionality I'm after is:</p>
  
  <ol>
  <li>Check if the list is empty in which case there can't be a player in it so just add one.</li>
  <li>If the list exists loop through it and look for the name of the objects.</li>
  <li>If the name exists, simply create the same player again but with its update values at the same index.</li>
  <li>The list exists but the name isn't found so just add the player.</li>
  </ol>
  
  <p>My code so far puts me in an never ending loop I'm guessing since the app stops responding. The split variable is one word split up from the asynchronous call which is the name, this I've checked by printing it. </p>