Convert Map Values from HashSet to List in Java

The following code shows show to convert a map values of HashSet type into List/ArrayList in Java:


import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Test {

	public static void main(String[] args) {
		HashSet<String> fruits = new HashSet<>();
		fruits.add("Grapes");
        fruits.add("Mango");
        fruits.add("Apple");
        fruits.add("Papaya");
        fruits.add("Pineapple");
        
        HashSet<String> flowers = new HashSet<>();
		flowers.add("Tulip");
        flowers.add("Rose");
        flowers.add("Sunflower");
        flowers.add("Marigold");
 
        Map<String, Object> map = new HashMap<>();
        map.put("fruits", fruits);
        map.put("flowers", flowers);
                
        
        Set<String> newSet = new HashSet<>();
		map.values().forEach(m->{
            newSet.addAll((Set)m);
        });
        List<String> list = new ArrayList<>(newSet);
        System.out.println(list);
    }
}    
Output:
[Apple, Tulip, Grapes, Papaya, Mango, Rose, Pineapple, Sunflower, Marigold]