How to Map two List Of type String in third List of Object [closed]

You could do:

List<Person> res = IntStream.range(0, firstName.size())
                            .mapToObj(i -> new Person(firstName.get(i), lastName.get(i)))
                            .collect(Collectors.toList());

However this is assuming both List‘s are the same size

This solution uses IntStream::range to generate a Stream of indices for the two List‘s

Browse More Popular Posts

Leave a Comment