title: How to check that List<Long> contains a value?
body: <p>I have list <code>List&lt;Long&gt; list</code>, that contains: [160774, 7212775] and <code>Long id = 7212775</code>. I need to check if the list contains an element with value of <code>id</code>. How to do that? Unfortunately <code>list.contains(id)</code> returns <code>false</code> in my case.</p>
  
  <p>I'm using it that way:</p>
  
  <pre><code>@RequestMapping("/case/{id}")
  public String openCase(@PathVariable("id") Long id) {
  
      log.debug(caseDAO.findAllCasesId());    // [160774, 7212775]
      log.debug(id); // 7212775
  
      if(caseDAO.findAllCasesId().contains(id)) {
          return "case";
      } else {
          return "404";
      }
  }
  </code></pre>
  
  <p>Piece of DAO (Hibernate, but native sql here):</p>
  
  <pre><code>public List&lt;Long&gt; findAllCasesId() {
      String sql = "select id from cases";
      SQLQuery query = getSession().createSQLQuery(sql);
      return query.list();
  }
  </code></pre>
  
  <hr>
  
  <p><strong>SOLVED</strong></p>
  
  <p>The problem was with <code>caseDAO.findAllCasesId()</code>, that return list of <code>Object</code>, not list of <code>Long</code>. I corrected this by:</p>
  
  <p><code>SQLQuery query = getSession().createSQLQuery(sql).addScalar("id", Hibernate.LONG);</code></p>
  
  <p>Big thanks to: <a href="https://stackoverflow.com/users/839689/nayuki-minase">Nayuki Minase</a></p>