title: Generate ID which is not taken by an object in a List
body: <p>I have a List with entities. Each entity has the attribute uuid and some others. Now I want to create a Entity Manager. The Manager can create new entities and has to look for a new unused id for the entity based on a List of all entities. This is my current approach: </p>
  
  <pre><code>@AllArgsConstructor
  public class Entity {
  
      @Getter @Setter
      private long id;
  
  }
  </code></pre>
  
  <pre><code>public class EntityManager {
  
      private static final MAX_AMOUNT_UUID = Setting.getInstance().getAmountUUID();
  
      private List&lt;Entity&gt; entities;
      private long lowestUnassignedEid;
  
      public EntityManager() {
          entities = new ArrayList&lt;&gt;();
          lowestUnassignedEid = 0;
      }
  
      public long generateNewEid(){
          if (lowestUnassignedEid &lt; MAX_AMOUNT_UUID ) {
              return lowestUnassignedEid++;
          } else {
             // How to check after this. 
             // a lot of the entities will be removed so there are a lot of free uuid
             // but how can find out ? 
          }
      }
  
      public Entity createEntity(){
           Entity e = new Entity(generateNewEid());
           entities.add(e);
           return e;
      }
  
      public void removeEntity(Entity entity){
          this.entities.remove(entity);
      }
  }
  </code></pre>
  
  <p>The more I think about it, it tend to use a Map instead. So I can check if a Number is in the KeySet. Or is there a proper way with a List? </p>