I'm trying to convert Map> to a List/Set of Strings in single line but couldn't do it unless I use traditional forEach for map. Is anyone aware to do it in single line using streams.
import java.util.*;
public class StreamDemo {
public static void main(String[] args) {
HashMap<String, List<String>> map = new HashMap<>();
ArrayList<String> s1 = new ArrayList<>();
map.put("A", Arrays.asList("A1, A2"));
map.put("B", Arrays.asList("B1, B2"));
map.put("C", Arrays.asList("C1, C2"));
Set<String> stringValues = new HashSet<>();
// LOGIC TO GET ALL VALUES A1, A2, B1, B2, C1, C2 INTO stringValues
System.out.println(stringValues);
// Expected output
// [A1, A2, B1, B2, C1, C2]
}
}