title: Which datastructure to store logged in users?
body: <p>I'm implementing a web application and on the serverside I need to keep track of logged in users. I've implemented a simple Authentication class for this, with methods for logging in/out.</p>
  
  <pre><code>public class AuthenticationServiceImpl extends RemoteServiceServlet implements AuthenticationService {
  
      private final List&lt;User&gt; currentlyLoggedIn = new ArrayList&lt;User&gt;();
  
      @Override
      public User login(String username, String password) {
              // retrieve user from DB if exists
          // add the user to the list/set/whatever
      }
  
      @Override
      public void logout(User user) {
              // remove the user from the datastructure
      }
  }
  </code></pre>
  
  <p>Now, I wonder which datastructure would be best to use? First I was thinking of a <code>List</code>, but as the order doesn't matter, and I need fast add/remove capabilities, I'm now thinking that a <code>HashMap</code>, using the <code>username</code> as the key and the <code>User</code> object as the value would be a better option. Any ideas/suggestions?</p>