0
Map<String, List<String>> mapValues; //some values
List<String> listValues;
listValues.addAll(mapValues.values()); // trying to add map values to list

I am currently achieving using for loop using map.values(), But I wanted to directly add it to a single list.

1 Answer 1

4

Just keep using the loop, it's the right tool for the job.

Each map key here points to a List<String>, so when you call .values() you're getting a List<List<String>>.

Apex does not have a way to reduce the dimensionality of a nested data structure (i.e. to go from a List<List<String>>, a 2-dimensional structure; to a List<String>, a 1-dimensional structure). You're going to need to add each list one at a time to your resulting (flattened) list.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .