转载 模糊查询map中的key

    public  Map<String, String> parseMapForFilter(Map<String, String> map, String filters) {
        if (map == null) {
            return null;
        } else {
            map = map.entrySet().stream()
                    .filter((e) -> checkKey(e.getKey(), filters))
                    .collect(Collectors.toMap(
                            (e) -> (String) e.getKey(),
                            Map.Entry::getValue
                    ));
        }
        return map;
    }

    private  boolean checkKey(String key, String filters) {
        return key.contains(filters)
    }

看起来能直接用在流里面

    public  Map<String, String> parseMapForFilter(Map<String, String> map, String filters) {
        if (map == null) {
            return null;
        } else {
            map = map.entrySet().stream()
                    .filter((e) ->e.getKey().contains(filters))
                    .collect(Collectors.toMap(
                            (e) -> (String) e.getKey(),
                            Map.Entry::getValue
                    ));
        }
        return map;
    }

https://blog.csdn.net/tr1912/article/details/90079591

原文地址:https://www.cnblogs.com/funkboy/p/13446669.html