0

I have a List of type <List> as below

private List<List<String>> strListOfList = new ArrayList<List<String>>();
strListOfList = [[A], [B], [C, D, E, F, G], [H, I, J, K, L]]

I need to convert this to a List of String as below

List<String> strList = new ArrayList<String>();
strList = [A,B,C,D,E,F,G,H,I,J,K,L]
 
 

Can someone help me how can i achieve this? I tried different solutions. But it is not working as expected.

PV_PN
  • 103
  • 2
  • 7
  • 3
    `strListOfList.stream().flatMap(Collection::stream).collect(Collectors.toList())`. – Boris the Spider Jun 29 '20 at 20:14
  • For future reference, this operation is often called flattening, so that might help your future searches. In general, I would recommend familiarizing yourself with Java's stream libraries. They're a concise and general way to describe data transformations. They compose much better than writing the loops by hand. – Riley Jun 29 '20 at 20:21

0 Answers0