Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
Partition list to sub lists in Java8

I'm wondering if there is any nice a way using Java 8 to do something like this:

int amount = 1000;
int firstIndex = 0;
int lastIndex = firstIndex + amount;
List<int> projectIdsList;

while (lastIndex < projectIdsList.size()){
        doSomethingWhitSubList(projectIdsList.subList(firstIndex, lastIndex));
        firstIndex = lastIndex;
        lastIndex = firstIndex + amount;
}
doSomethingWhitSubList(projectIdsList.subList(firstIndex,  projectIdsList.size());
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can partition the list into sublist using IntStream, and I'm not really sure about your intention after partition, but you can collect the sublist's into a list using collect

List<List<Integer>> subLists = IntStream.range(0,integers.size())
            .filter(i->i%amount == 0)
            .mapToObj(i->integers.subList(i,i+amount > integers.size() ? integers.size() : i+amount))
            .collect(Collectors.toList());

Or you can also use forEach for any operations after partitioning

IntStream.range(0,integers.size())
            .filter(i->i%amount == 0)
            .mapToObj(i->integers.subList(i,i+amount > integers.size() ? integers.size() : i+amount))
            .forEach(this::doSomethingWhitSubList);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda