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

285
Vistas
How to convert the values of a Map of List to a single List

How is the best (efficient and simple) way to convert the values of a Map<Object1, List<Object2>> to a List<Object2>. Should I simply iterate over all entries and adAll the items to a list?

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Here's a third way so you don't need to create an ArrayList, which is what you actually asked. This is the proper way to use streams because you're not changing the state of any object.

List<Object2> values = myMap.values()
                            .stream()
                            .flatMap(Collection::stream)
                            .collect(Collectors.toList());
about 4 years ago · Santiago Trujillo Denunciar

0

Just found it:

 List<Object2> list = myMap.values()
                           .stream()
                           .flatMap(item -> item.stream())
                           .collect(Collectors.toList()));
about 4 years ago · Santiago Trujillo Denunciar

0

One option using addAll.

List<Object2> list = new ArrayList<>();
myMap.values().forEach(list::addAll);
about 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