title: How to convert a ArrayList of Objects into List of Integer in java
body: <p>I used this native query to fetch data. <code>
  select c.id,c.name from customer c,information i where i.status=1 and c.id=i.customerId
  </code>
  and  i used the below code to convert the object list into integer list as  </p>
  
  <pre><code>public List&lt;Integer&gt; getAllIdsByGroupId(Integer groupId) throws Exception {
      List&lt;Object[]&gt; list = repository.getAllIdsByGroupId(groupId);
      List&lt;Integer&gt; ids = repository.mapIds(list);
      return ids;
  }
  
  
  public List&lt;Object[]&gt; getAllIdsByGroupId(Integer groupId) {  
      Query query = entityManager.createNativeQuery("select c.id,c.name from customer c,information i where i.status=1 and c.id=i.customerId and c.groupId=:groupId");
      query.setParameter("groupId", groupId);
      List&lt;Object[]&gt; list = query.getResultList();
      if (list == null || list.isEmpty()) {
          return null;
      }
      return list;
  }
  
  
  public List&lt;Integer&gt; mapIds(List&lt;Object[]&gt; list) {
      List&lt;Integer&gt; ids = new ArrayList&lt;Integer&gt;();
      if (list != null &amp;&amp; !list.isEmpty()) {
          Integer id;
          for (Object[] object : list) {
              id = (object[0] != null ? (Integer) object[0] : null);
              ids.add(id);
          }
      }
      return ids;
  }
  </code></pre>
  
  <p>The query retrieves a list with id and name.and the above code gives output without exception.But i require List with only ids.    when i remove c.name from query as follows<code>
  select c.id from customer c,information i where i.status=1 and c.id=i.customerId
  </code> the above code fails and produce the exception </p>
  
  <pre><code>java.lang.Integer cannot be cast to [Ljava.lang.Object;
  </code></pre>
  
  <p>Any helps? thanks in advance.</p>