for(int i = 0 ; i < 2000; i++){ ids.add(i); } Listresult = new ArrayList<>(); Map map = new HashMap<>(); for(int limit = 500,skip = 0 ; skip < ids.size(); skip = skip+ limit){ List idList = ids.stream().skip(skip).limit(limit).collect(Collectors.toList()); result.addAll(idList); }