[Solved] Flattening nested list in java [closed]


It seems that a raw list/array needs to be created including fields from Employee and Address (assuming appropriate getters exist in these classes):

List<List<Object>> flattened = list.stream()
    .flatMap(emp -> emp.getAddresses().stream()
        .map(addr -> Arrays.asList(
            emp.getName(), emp.getId(), 
            addr.getAddress(), addr.getPostalCode()
        ))
    )
    .collect(Collectors.toList());

flattened.forEach(System.out::println); // should print desired result

solved Flattening nested list in java [closed]