Set<User> a = c.getUsers(); Iterator<User> x = a.iterator(); users = new Long[a.size()]; while (x.hasNext()) { b = x.next(); users[i]=b.getId(); System.out.println(users[i]+"aa"); i++; }