- 
                Notifications
    You must be signed in to change notification settings 
- Fork 4
Java Stream filter map by values example
        Ramesh Fadatare edited this page Jul 11, 2019 
        ·
        1 revision
      
    In this Java example, we filter a map by its values.
In the example, we filter out two countries from the map.
import java.util.HashMap;
import java.util.Map;
public class JavaStreamFilterMapByValues {
    public static void main(String[] args) {
        Map<String, String> hmap = new HashMap<>();
        hmap.put("de", "Germany");
        hmap.put("hu", "Hungary");
        hmap.put("sk", "Slovakia");
        hmap.put("si", "Slovenia");
        hmap.put("so", "Somalia");
        hmap.put("us", "United States");
        hmap.put("ru", "Russia");
        hmap.entrySet().stream().filter(map -> map.getValue().equals("Slovakia")
                || map.getValue().equals("Slovenia"))
                .forEach(m -> System.out.println(m));
    }
}Output:
si=Slovenia
sk=Slovakia