how concat each element from two lists to a new one?

I have to list one with Cds and other with names

final List<String> Cds = listSiccdsByRegion.stream().map(sic -> (String)sic.get(0)).collect(Collectors.toList()); 

Output :0 1 2 3

final List<String> names = listSiccdsByRegion.stream().map(sic -> (String)sic.get(1)).collect(Collectors.toList());

Output : Jhon doe data dummy

Is there is a way to convince both element and return a list joining like this?


Cds Names
0 Jhon
1 Doe
2 Dummy
3 Data

Upvotes: 0

Views: 79

Answers (1)

Ravindra Ranwala
Ravindra Ranwala

Reputation: 21124

Based on the assumption that listSiccdsByRegion is of type List<List<String>> you may solve it as shown below. The trick here is that you can use the map operator to convert it into the required format.

List<String> result = listSiccdsByRegion.stream()
    .map(sic -> sic.get(0) + " " + sic.get(1))
    .collect(Collectors.toList());

Upvotes: 2

Related Questions